John W. Vinson <jvinson@STOP_SPAM.WysardOfInfo.com> wrote in
news:(E-Mail Removed):
> It looks like a lot of code
If you want a simple replacement for DoCmd.RunQuery without writing
new code, see my SQLRun() function after my signature. It's been in
production use in my apps for several years now, and I use it
instead of writing an error handler each time I need to use .Execute
to run DML SQL.
--
David W. Fenton
http://www.dfenton.com/
contact via website only
http://www.dfenton.com/DFA/
Public Function SQLRun(strSQL As String, Optional db As Database, _
Optional lngRecordsAffected As Long) As Long
On Error GoTo errHandler
Dim bolCleanup As Boolean
If db Is Nothing Then
Set db = CurrentDb
bolCleanup = True
End If
db.Execute strSQL, dbFailOnError
lngRecordsAffected = db.RecordsAffected
exitRoutine:
If bolCleanup Then
Set db = Nothing
End If
SQLRun = lngRecordsAffected
'Debug.Print strSQL
Exit Function
errHandler:
MsgBox "There was an error executing your SQL string: " _
& vbCrLf & vbCrLf & Err.Number & ": " _
& Err.Description, vbExclamation, "Error in mdlDWF.SQLRun()"
Debug.Print "SQL Error: " & strSQL
Resume exitRoutine
End Function