Skip to content
Advertisement

Why is my Me. Reference and INSERT INTO causing error?

I am receiving two errors when attempting to create a query which updates my audit log after an update is made to a record.

First I am prompted to enter a Parameter Value where I believed my ME. code would point to any record with the current value of field [Corrected Med Ed ID].

Secondly I receive message:

Syntax error in INSERT INTO statement.

My form’s code is –

Advertisement

Answer

Simply use parameterized queries and avoid the need to concatenate SQL string in VBA. Specifically, save below two SQL statements as stored Access queries. Then bind parameters using QueryDefs in VBA for cleaner, readable, and maintainable code.

Note: the two update queries can be combined into one. Also, the table alias, t, is used. When using Query Design, Access will not allow you to save queries with syntax error. Below assumes parameter will be a string/text value.

SQL

Update Query

Append Query

VBA (no concatenation)

Or DRY-er approach:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement