I have googled this error message and a lot of people have similar problems, but with different code layouts. I've tried copy and pasting as a last resort to get this code to work, but I always get the same error when running adodb and dao. Here is my code which I've typed out rather than copy and paste. I've installed Access runtime and have Microsoft Activex Dataobjects 6.1 enabled.
Sub DBOilChanges()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sQRY As String
Dim strFilePath As String
strFilePath = "C:\Users\*user*(I removed my drive name for this thread)\Desktop\db.accdb (i removed the db name for this thread)"
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFilePath & ";"
sQRY = "SELECT * FROM InvoiceOilChanges (my query name exactly spelled);"
rs.CursorLocation = adUseClient
rs.Open sQRY, conn, adOpenStatic, adLockReadOnly (<--- this is where i revieve the error message)
Application.ScreenUpdating = False
Sheets1.Range("A1").CopyFromRecordset rs
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
Exit Sub
End Sub
I've tried, i feel like, everything. Any ideas? Thanks.
Bookmarks