0

I am trying to run a query in Microsoft Access in Excel VBA. I get the error "Syntax Error in FROM Clause". Where am I going wrong?

Dim conn as ADODB.connection
Dim thisSQL as string
thisSQL = "SELECT Column FROM QueryName WHERE [Column] = Test;"
Set conn = new ADODB.Connection
with conn
.connectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Z:\AXIS Conversion\FIA FAS 133 Documentation\AVRF Validation\AVRF Testing Database.accdb;"
.open
.execute thissql, ,adcmdtext

I've tried many variation in my SQL code by adding/removing semi colon, adding/removing brackets, etc. Thanks!

2
  • 1
    Table has field named "Column"? If [Column] is a text type field, need apostrophe delimiters: WHERE [Column]='Test';". Also, Execute is for action SQL (DELETE, INSERT, UPDATE). Need a recordset object for SELECT. Commented Jul 11, 2020 at 23:15
  • 1
    Also, Column is a reserved word. Should not use reserved words as names. If you do, enclose in [ ]. Commented Jul 11, 2020 at 23:24

1 Answer 1

0

I think you are comparing the column value incorrectly. Try putting value Test in single quote as

thisSQL = "SELECT Column FROM QueryName WHERE [Column] = 'Test';"

Instead of

thisSQL = "SELECT Column FROM QueryName WHERE [Column] = Test;"

Also verify running the same query in access directly.

Sign up to request clarification or add additional context in comments.

1 Comment

Answer is only partial solution as there are multiple issues with code.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.