Error Handling - Docmd.RunSQL (1 Viewer)

AccessNub

Registered User.
Local time
Today, 09:13
Joined
Jul 22, 2006
Messages
71
Hi Guys,

I have an Onclick button that appends info to another db. On occasion, the sql doesn't work.

I was thinking of adding some sort of error handling to this to try to alert the user when it fails. It never effects the same user and its somewhat random. Out of 200, I'd say 1 or 2 do not make it to the back db.

I have never tried to use error handling and was hoping for some help. Whill this work for a failed DoCmd.RunSQL? Here is what i have so far. For space, I have taken out the "StrSQL =" part since its a very long line.

Sub Backup()
On Error Goto Error_Handle
Me.Dirty = False
DoCmd.RunSQL StrSQL
DoCmd.SetWarnings True
Error_Handle:
Msgbox "Backup has failed"
End Sub
 

KenHigg

Registered User
Local time
Today, 12:13
Joined
Jun 9, 2004
Messages
13,327
Put something like the following inthe error handler:

msgbox err.number

This should tell you what you error code is. Then in the error handler, put something like the following:

if err.number = >What ever the error number was< then
msgbox "File did not upload msg"
end if
 

AccessNub

Registered User.
Local time
Today, 09:13
Joined
Jul 22, 2006
Messages
71
Put something like the following inthe error handler:

msgbox err.number

This should tell you what you error code is. Then in the error handler, put something like the following:

if err.number = >What ever the error number was< then
msgbox "File did not upload msg"
end if


Great idea. With that I can write the error to a table and check a box showing that it errored and why.
 

Users who are viewing this thread

Top Bottom