VBA Cursor with Query referencing a form

  • Thread starter Thread starter Ed Carron
  • Start date Start date
E

Ed Carron

I have a cursor which opens based on a stored query. If the query
references an object on a form, I get an error when executing it: "Invalid
SQL statement; expected 'DELETE','INSERT','PROCEDURE','SELECT', or 'UPDATE'.
When I remove the reference to a form from the query, the cursor runs fine.

Anybody know why this happens and what I can do to fix this?

Thanks,
Ed
 
In VBA, you need to resolve the reference to the Form Control before passing
the Query / SQL String to the Database Engine for execution.

The reason is that the database engine does not know about the Form
Controls. This is different from running a Query using the GUI (i.e.
Query-By-Example interface) since in this case, the Expression Service
automatically steps in and resolve the reference to the Form Control before
passing the SQL String to the Database Engine for execution.

You can use the Parameters Collection of the QueryDef Object to resolve the
reference to the Form Control (which is a Parameter in the Query).
 
Back
Top