I am trying to SELECT information from a sheet in Excel into a DAO Recordset. When I run the code on one computer, it works perfectly fine. When I run the code on another computer with a similar load and all of the same references checked, I get the following error:
Run-time error 3011: The Microsoft Jet database engine could not find the object 'Sheet1$'. Make sure the object exists and that you spell its name and the path name correctly.
What is odd is that the computer which errors out recognizes the sheet if I try to activate or select it, but it doesn't seem to like the syntax [Sheet1$], which is required to run the SQL statement. I have also tried 'Sheet1$', which is acceptable. Neither works.
Here is the code:
Sub ProcessRecordset(Destination As Worksheet)
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strFile As String
Dim strSQL As String
Dim wsSource, wsDestination As Worksheet
On Error GoTo 0
strFileName = Application.ActiveWorkbook.Name
Set db = OpenDatabase(strFileName, False, False, "Excel 8.0;HDR=Yes;")
strSQL = "TRANSFORM Sum(Volume) As SumOfVolume"
strSQL = strSQL & " SELECT CorpName, Cat"
strSQL = strSQL & " FROM [Sheet1$]"
strSQL = strSQL & " WHERE Prod = 'Product'"
strSQL = strSQL & " GROUP BY CorpName, Cat"
strSQL = strSQL & " ORDER BY CorpName, Cat, ProdDate"
strSQL = strSQL & " PIVOT ProdDate;"
Set rst = db.OpenRecordset(strSQL)
Destination.Range("A8").CopyFromRecordset rst
rst.Close
Set rst = Nothing
db.Close
Set db = Nothing
End Sub
Any help would be greatly appreciated. It is frustrating that it works perfectly fine on one computer and does not work on another computer that is nearly identical (though clearly different in some way). We have checked the MDAC version to both and applied the most recent Microsoft updates to both computers... this does not fix the issue.
Run-time error 3011: The Microsoft Jet database engine could not find the object 'Sheet1$'. Make sure the object exists and that you spell its name and the path name correctly.
What is odd is that the computer which errors out recognizes the sheet if I try to activate or select it, but it doesn't seem to like the syntax [Sheet1$], which is required to run the SQL statement. I have also tried 'Sheet1$', which is acceptable. Neither works.
Here is the code:
Sub ProcessRecordset(Destination As Worksheet)
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strFile As String
Dim strSQL As String
Dim wsSource, wsDestination As Worksheet
On Error GoTo 0
strFileName = Application.ActiveWorkbook.Name
Set db = OpenDatabase(strFileName, False, False, "Excel 8.0;HDR=Yes;")
strSQL = "TRANSFORM Sum(Volume) As SumOfVolume"
strSQL = strSQL & " SELECT CorpName, Cat"
strSQL = strSQL & " FROM [Sheet1$]"
strSQL = strSQL & " WHERE Prod = 'Product'"
strSQL = strSQL & " GROUP BY CorpName, Cat"
strSQL = strSQL & " ORDER BY CorpName, Cat, ProdDate"
strSQL = strSQL & " PIVOT ProdDate;"
Set rst = db.OpenRecordset(strSQL)
Destination.Range("A8").CopyFromRecordset rst
rst.Close
Set rst = Nothing
db.Close
Set db = Nothing
End Sub
Any help would be greatly appreciated. It is frustrating that it works perfectly fine on one computer and does not work on another computer that is nearly identical (though clearly different in some way). We have checked the MDAC version to both and applied the most recent Microsoft updates to both computers... this does not fix the issue.