I've been coding a module to import an access database query (hopefully several in the future) into an excel worksheet but keep on getting the same error:
Run-time error '-2147217900 (80040e14)': Syntax error in FROM clause.
The code I am using to import the database query is below:
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sQRY As String
Dim strFilePath As String
strFilePath = "P:\DIRT V6-4 W10.accdb"
Set cnn = New ADODB.Connection
Set rs = New ADODB.Recordset
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & strFilePath & ";"
sQRY = "SELECT * FROM AIS jobs outstanding"
rs.CursorLocation = adUseClient
rs.Open sQRY, cnn, adOpenStatic, adLockReadOnly
Application.ScreenUpdating = False
Sheet1.Range("A1").CopyFromRecordset rs
rs.Close
Set rs = Nothing
cnn.Close
Set cnn = Nothing
Exit Sub
End Sub
Any idea what the issue solution could be? I have not used vba/sql in some time and any help would be of use. Thanks.