ich hänge gerade an einer bestimmten Stelle in meinem Code und komme nicht mehr weiter. Und zwar hab ich eine Access angebunden und will da bestimmte Auswertungen machen (deskriptiv vor allem usw). Jetzt will ich z.B. eine bestimmte Kennzahl auswerten und zieh mir dazu zwei bestimmte Werte aus mittels SQL Abfrage aus der DB und will diese dann entsprechend weiterverarbeiten, also in einer Formel verrechnen. Ich kenn meine Ergebnisse bei den SQL Abfragen und die sind beide nicht NULL. Allerdings gibt mir Excel lokal meine Variablen als NULL an und ich kann sie deshalb nicht weiter verrechnen. Sieht jemand einen Fehler?
Private Sub AOV()
Dim conn As New ADODB.Connection
Dim recset1 As New ADODB.Recordset
Dim recset2 As New ADODB.Recordset
Dim strDB As String
Dim fldCount As Integer
Dim recCount As Long
Dim AOV As Long
' Set the string to the path of your database
DBPATH = "C:\Users\Kathrin\Desktop\ba-scm_projekt\bike_sales.accdb"
'This is the connection provider. Remember this for your interview.
PRVD = "Microsoft.ace.OLEDB.12.0;"
'This is the connection string that you will require when opening the the connection.
connString = "Provider=" & PRVD & "Data Source=" & DBPATH
'opening the connection
conn.Open connString
'Read the dates provided by user
Dim startdate As String, enddate As String
Dim sday As Integer, smonth As Integer, syear As Integer
Dim eday As Integer, emonth As Integer, eyear As Integer
sday = Range("B5").Value
smonth = Range("C5").Value
syear = Range("D5").Value
eday = Range("B6").Value
emonth = Range("C6").Value
eyear = Range("D6").Value
startdate = syear & "_" & smonth & "_" & sday
enddate = eyear & "_" & emonth & "_" & eday
' Open recordset
recset1.Open "Select sum(profit) From Purchase_Orders where datum between 'startdate' and ' _
_
_
_
_
enddate'", conn
' Set active Worksheet
Worksheets("Average Order Value").Activate
' Copy sum of profit into worksheet
ActiveSheet.Cells(17, 7).CopyFromRecordset recset1
' Open recordset
recset2.Open "SELECT Count(*) FROM Purchase_Orders WHERE (Datum Between 'startdate' And ' _
enddate')", conn
' Copy count of purchase orders into worksheet
ActiveSheet.Cells(18, 7).CopyFromRecordset recset2
' Calculate AOV
AOV = Cells(17, 7).Value / Cells(18, 7).Value
Cells(18, 2).Value = AOV
' Close ADO objects
rst.Close
conn.Close
Set rst = Nothing
Set conn = Nothing
Set ActiveSheet = Nothing
End Sub