i have several tables in access. we want excel reports produced that can access the Access tables, determine min max ave etc, and create the excel reports. i can either bring the data in to a scratch worksheet or do it in memory. have been able to get the ADODB connection but system stops when i try to get the recordset.
Sub GetData()
Dim conn As Object, rst As Object
Dim sql As String, myCnt As Long
sql = "SELECT [DateAndTime], [TagIndex], [Val] " & _
"FROM " & strDataFile1 & _
" WHERE [DateAndTime] >= " & datFirst & _
" AND [DateAndTime] <= " & datLast & ";"
Set conn = CreateObject("ADODB.Connection")
With cn
.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0"
.Open strDataPath1
End With
Set rs = CreateObject("ADODB.Recordset")
With rs
Set .ActiveConnection = cn
.Source = MySql 'Pass your SQL
.Open , , 3, 3 '.Open , , adOpenStatic, adLockOptimistic
********code bombs out here *******
** error message says it is trying to find my target file xxx.mdb but is
** looking for it at c:\documents and settings\steve\my
** documents\xxx.mdb.
** but my strDataPath1 is D:\XL_Access\xxx.mdb
myCnt = .RecordCount
If myCnt > 0 Then
.MoveLast: .MoveFirst
'Pull data to first sheet, cells a1:RecordestCountRow & column 3 _
3 fields in the sql pass
wsDataFile1.Range(Cells(1, 1), Cells(myCnt, 3)).CopyFromRecordset rs
End If
.Close
End With
cn.Close
Set rs = Nothing: Set cn = Nothing
Stop
End Sub
Sub GetData()
Dim conn As Object, rst As Object
Dim sql As String, myCnt As Long
sql = "SELECT [DateAndTime], [TagIndex], [Val] " & _
"FROM " & strDataFile1 & _
" WHERE [DateAndTime] >= " & datFirst & _
" AND [DateAndTime] <= " & datLast & ";"
Set conn = CreateObject("ADODB.Connection")
With cn
.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0"
.Open strDataPath1
End With
Set rs = CreateObject("ADODB.Recordset")
With rs
Set .ActiveConnection = cn
.Source = MySql 'Pass your SQL
.Open , , 3, 3 '.Open , , adOpenStatic, adLockOptimistic
********code bombs out here *******
** error message says it is trying to find my target file xxx.mdb but is
** looking for it at c:\documents and settings\steve\my
** documents\xxx.mdb.
** but my strDataPath1 is D:\XL_Access\xxx.mdb
myCnt = .RecordCount
If myCnt > 0 Then
.MoveLast: .MoveFirst
'Pull data to first sheet, cells a1:RecordestCountRow & column 3 _
3 fields in the sql pass
wsDataFile1.Range(Cells(1, 1), Cells(myCnt, 3)).CopyFromRecordset rs
End If
.Close
End With
cn.Close
Set rs = Nothing: Set cn = Nothing
Stop
End Sub