Trapping Errors with Select Case

  • Thread starter Thread starter Bonnie
  • Start date Start date
B

Bonnie

Hi there. Using A02 on XP. Trying to trap 2 errors, had
3022 working but added 2169 and now I only get the error
numbers identified due because I have this:

Private Sub Form_Error(DataErr As Integer, Response As
Integer)
MsgBox "Error Number: " & DataErr
End Sub

Am I doing something wrong below?

Private Sub Form_Close()
Select Case Err.Number
Case 3022
MsgBox "A record containing the Plan Number and
Check Number you have keyed in already exists, please
check your data. Press the Escape Key twice to begin
another record."
Resume Next
Select Case Err.Number
Case 2169
MsgBox "This record cannot be saved."
Resume Next
Case Else
MsgBox Err.Description
Resume
End Select
End Select
End Sub

Also, one more question? What is the best way to 'clear'
the fields on a form if the above occurs?

Thank you in advance for any help or advice!!! LUV U GUYS!
 
You need to put Select Case in the code just once for the select block:

Private Sub Form_Close()
Select Case Err.Number
Case 3022
MsgBox "A record containing the Plan Number and
Check Number you have keyed in already exists, please
check your data. Press the Escape Key twice to begin
another record."
Resume Next
Case 2169
MsgBox "This record cannot be saved."
Resume Next
Case Else
MsgBox Err.Description
Resume
End Select
End Sub


Try Me.Undo to remove entered values. However, note that this may be too
late to do in the Close event.
 
Back
Top