I want to detect a duplicate key error when appending a record to a table.
I correctly construct an INSERT INTO sqlString, and then the following code gets executed:
On Error Resume Next
If Err = conDuplicateKey Then
when the docmd.runsql statement is executed and the duplicate key error happens, sql error message box(es) are displayed before the statement immediately following the docmd.runsql statement is reached, i.e. "within" the docmd itself, and then the err returned is
2501 , The RunSQL action was canceled
or 0 , depending on how I respond to the SQL error box options ...
1) how to avoid the docmd.runsql from announcing errors and instead passing the actual error back to the next VBA statement
2) if that's impossible with docmd, how best to accomplish this:
- if a record is in a table already, update it
else insert a record
3) in general, how to get docmd to be quiet ?