0

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.

JohnM
  • 2,422
  • 2
  • 8
  • 20
mblack204
  • 39
  • 5

1 Answers1

4

AIS jobs outstanding is causing the error because it contains spaces.

sQRY = "SELECT * FROM [AIS jobs outstanding]"
Matt
  • 14,906
  • 27
  • 99
  • 149