Skip to content
Advertisement

VBA SQL update/insert to local table using values from form

I am trying to update a row in a local table stored in access (or insert a new row if that ID doesn’t already exist) using values populated in a form by the user. I am writing it in VBA using SQL. Here is the code:

The code returns the following error message :

Run-time error ‘3129’, invalid SQL statement; expected ‘DELETE’, ‘INSERT’, ‘PROCEDURE’, ‘SELECT’, or ‘UPDATE’.

Advertisement

Answer

MS Access SQL does not support if statements, only iif statements.

As such, you’ll likely need to implement the logic within VBA, e.g.:

There are a few other issues:

  • stringSQL is a typo, since you initially define your variable as strSQL.
  • DoCmd.RunSQL (stringSQL) parentheses should not surround the argument since the expression is not part of another expression.
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement