Select Query Does Not Work When Converted To Vba - Invalid Sql Statement
I have been struggling with SQL statement when converted to VBA. Basically, I wish to add something to it before executing (which shouldn't be a problem). However, when I try to ru
Solution 1:
That error message is misleading. The real problem is that DoCmd.RunSQL is intended for "action" queries: UPDATE; INSERT; DELETE; etc.
It will not accept a plain SELECT query. For example, this simple SELECT query gives me that same "A RunSQL action requires an argument consisting of an SQL statement" message from DoCmd.RunSQL:
Dim SQLstr As String
SQLstr = "SELECT * FROM tblFoo;"
DoCmd.RunSQL SQLstr
However, DoCmd.RunSQL executes this valid UPDATE statement without error:
SQLstr = "UPDATE tblFoo SET long_text='bar' WHERE id=1;"
DoCmd.RunSQL SQLstr
You need a different method to use your SELECT query. And the choice of method depends on what you want to do with the results returned by the query.
Post a Comment for "Select Query Does Not Work When Converted To Vba - Invalid Sql Statement"