PC Review


Reply
Thread Tools Rate Thread

Catching Errors | 3021, 2766, ETC | Need Help!

 
 
JK
Guest
Posts: n/a
 
      11th Jun 2009
In most of my forms I have a before update event that make sure certain
information has been entered before allowing the user the ability to save the
form. For example, in my Contacts form when adding a new contact, the user
must provide a last name. If a last name is not entered and the form is saved
or closed the user gets a pop-up message telling them they cannot continue.

This works great except for the fact that I'm getting an error after the
MsgBox. The errors seem to be usually 3021 or 2766 but I've seen others.

I'm using the SaveIt function in these forms. Below I've pasted the Before
Update Event and the SaveIt function. I've tried catching the errors
everywhere I would think to catch them but it doesn't seem to work.

I'd like to be able to surpress the error message and prevent a record from
being added to the ErrorLog Table via the SaveIt function.

Hope this all makes sense; I'm using Access 2003.
Any help would be greatly appreciated.


Private Function SaveIt() As Integer
Dim lngErr As Long, strError As String

' Common Save routine called from cmdSave and a couple of other places

' Default: We expect this to work
SaveIt = True
' No need to do anything if the form isn't "dirty"
If (Me.Dirty = True) Then
' OK, gonna try to save - set error trap
On Error GoTo Save_Error
Me.Dirty = False ' Force a save by resetting Dirty
End If

Save_Exit:
Exit Function

Save_Error:
' Got here if the save failed. Handle most common errors
' (Some may be handled by Form_Error instead)
SaveIt = False ' Indicate save failed
' Try to analyze the error
Select Case Err
Case errCancel, errCancel2, errPropNotFound ' Cancel - ignore
Resume Save_Exit
Case errDuplicate ' Duplicate row - custom error message
MsgBox "You're trying to add a record that already exists. " & _
"Enter a new Issue or click Cancel.", vbCritical, "Attention!"
Case errInvalid, errInputMask
' Invalid data - custom error and log
MsgBox "You have entered an invalid value. ", vbCritical,
"Attention!"
ErrorLog Me.Name & "_Save", Err, Error
' Field validation, Table validation, Custom Validation, End of
Search, Spelling Check
Case errValidation, errTableValidate, errCustomValidate,
errSearchEnd, errSpellCheck
' Display the error
' All validation rules in the tables have custom error messages.
MsgBox Error, vbCritical, "Attention!"
Case Else
' Dunno - log and let error display
' Save the error code values because ErrorLog may get additional
errors
lngErr = Err
strError = Error
ErrorLog Me.Name & "_Save", lngErr, strError
MsgBox "Error attempting to save: " & lngErr & " " & strError &
Chr$(13) & Chr$(10) & "Try again or click Cancel to close without saving.",
48, "Attention!"
End Select
Resume Save_Exit
End Function
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
catching all errors =?Utf-8?B?cm9kY2hhcg==?= Microsoft ASP .NET 6 20th Nov 2006 01:19 PM
Catching errors cbh35711 Microsoft Excel Programming 0 3rd Apr 2006 09:52 PM
How to catching DLL run-time errors in VB.net? R. MacDonald Microsoft VB .NET 0 12th Jan 2006 01:20 PM
Catching network errors Sam Evans Microsoft C# .NET 0 20th Jan 2005 05:24 PM
Catching ASP.NET errors Mikael Engdahl Microsoft ASP .NET 3 15th Aug 2003 07:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:03 PM.