gbshahaq
Sham
- Local time
- Today, 09:07
- Joined
- Apr 21, 2004
- Messages
- 52
Hi
i've been using ADO recordsets for loading data from Access to Excel for some time with no issues - until now.
i set up the following Function in Excel to use as a general module for importing data from like-named queries in my Access db (Access 2000)
There is definitely data in the queries, and can fetch data using ODBC/Query Wizard with no issues. However, using the code below i only get the field names and no data (no errors either...) - it's as if the recordset is empty?
Please help...getting rather annoyed right now....
i've been using ADO recordsets for loading data from Access to Excel for some time with no issues - until now.
i set up the following Function in Excel to use as a general module for importing data from like-named queries in my Access db (Access 2000)
There is definitely data in the queries, and can fetch data using ODBC/Query Wizard with no issues. However, using the code below i only get the field names and no data (no errors either...) - it's as if the recordset is empty?
Please help...getting rather annoyed right now....

Code:
Function BaseImport(SheetName As String)
Dim cn As ADODB.Connection, rs As ADODB.Recordset, strSQL As String, TR As Range, DSrc As String
Dim QryName As String
Set TR = Range(SheetName & "!A1")
Set TR = TR.Cells(1, 1)
DSrc = "\\server1\files\Scorecard.mdb"
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DSrc & ""
QryName = "qry_MTH_" & SheetName
strSQL = " SELECT * FROM " & QryName
'Debug.Print strSQL
Set rs = New ADODB.Recordset
rs.Open strSQL, cn
For intcolindex = 0 To rs.Fields.Count - 1
TR.Offset(0, intcolindex).Value = rs.Fields(intcolindex).Name
Next
TR.Offset(1, 0).CopyFromRecordset rs
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Function