WalkieTalkie
Technical User
Essentially, I want to replace the default MS error message that comes up in response to err.number 2169, but am having a ridiculous amount of trouble with it!
I want to add some error handling to a form that will deal with the user who tries to close the form using the top right hand x button without having entered the employee number in the subform. Currently, I have got it so that when this happens, a custom error message comes up saying "You must enter employee number". The only option is an OK button. Then my custom message comes up saying "If you close this now you will lose the data. Click cancel if you don't want to close". OK and Cancel buttons. When the user click OK, the form closes fine - everything's sweet. But when the user clicks cancel, to try and return to the form, the confounded default message pops up as well. ("You can't save this record at this time..."
Here is my code:
Why am I having so much trouble with this? What am I missing? Any help will be appreciated.
Regards
Miranda
I want to add some error handling to a form that will deal with the user who tries to close the form using the top right hand x button without having entered the employee number in the subform. Currently, I have got it so that when this happens, a custom error message comes up saying "You must enter employee number". The only option is an OK button. Then my custom message comes up saying "If you close this now you will lose the data. Click cancel if you don't want to close". OK and Cancel buttons. When the user click OK, the form closes fine - everything's sweet. But when the user clicks cancel, to try and return to the form, the confounded default message pops up as well. ("You can't save this record at this time..."
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case 3101
DoCmd.Beep
MsgBox "You must enter or select an employee name", , "Sorry - this record has no name."
Me.cmbEmployeeNo.SetFocus
Response = acDataErrContinue
Case 2169
If MsgBox("This form will close.@The data you have entered will not be saved." & Chr(10) & "Select Cancel if you do not want this form to close@@19@@2", vbOKCancel, "Sorry - can't save this record") = vbCancel Then
Me.cmbEmployeeNo.SetFocus
Exit sub
Else
Response = acDataErrContinue
End If
End Select
End Sub
Regards
Miranda