ADO Automation Error
Hi Eric,
I have a spreadsheet with a similar routine. In the section where you have
the error occur I have mine setup as follows (I've used the names from your
example):
rstAssigns.Open strSelect, conData, adOpenStatic, adLockReadOnly, adCmdText
Your sheet name reference does look correct.
Here's the whole routine as I had set it up. It's structured a bit different
from yours, but that shouldn't be an issue.
Sub QueryExcelSupersheet()
'create the connection string
Dim ConnectionString As String
ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;" & _
"Data Source=K:\ADO\SUPERSH.xls;" & _
"Extended Properties=Excel 8.0;"
'create the sql query
Dim MyQuery As String
MyQuery = "SELECT * " & _
"FROM [Today$] "
'create the recordset
Dim MyRS As ADODB.Recordset
Set MyRS = New ADODB.Recordset
'open the recordset
MyRS.Open MyQuery, ConnectionString, adOpenStatic, adLockReadOnly,
adCmdText
Sheets("xl data").Activate
ActiveSheet.Range("A1").CopyFromRecordset MyRS
MyRS.Close
Set MyRS = Nothing
End Sub
Hopefully this helps.
|