The problem with DoCmd.RunSQL is that it ignores any errors.
I have posted many times my SQLRun code, which can be used as a
drop-in replacement for DoCmd.RunSQL. Put the code after my
signature in a public module and then search and replace to change
DoCmd.RunSQL to SQLRun.
SQLRun also returns the count of records affected, should you decide
to use it as a function instead of as a sub.
--
David W. Fenton
http://www.dfenton.com/
usenet at dfenton dot com
http://www.dfenton.com/DFA/
Public Function SQLRun(strSQL As String, _
Optional db As DAO.Database, _
Optional lngRecordsAffected As Long) As Long
On Error GoTo errHandler
If db Is Nothing Then Set db = dbLocal
DBEngine.Workspaces(0).BeginTrans
db.Execute strSQL, dbFailOnError
lngRecordsAffected = db.RecordsAffected
DBEngine.Workspaces(0).CommitTrans
exitRoutine:
SQLRun = lngRecordsAffected
Exit Function
errHandler:
MsgBox "There was an error executing your SQL string: " _
& vbCrLf & vbCrLf & Err.Number & ": " & Err.Description, _
vbExclamation, "Error in SQLRun()"
Debug.Print "SQL Error: " & strSQL
DBEngine.Workspaces(0).Rollback
Resume exitRoutine
End Function