theKruser
Registered User.
- Local time
- Today, 14:53
- Joined
- Aug 6, 2008
- Messages
- 122
I am trying to create a custom error message. I am getting a very odd response. On error, I get an Access-generated Runtime error '3022'. If I hit End then try to close the form, I get my custom error message.
The first text box on the form is for Employee ID. After update, it should be validated and if duplicate, show the custom error message. The Access message should not show at all. Can someone please have a look at this an help me understand where I am going wrong?
Here is what I have:
To duplicate the problem, open frmAddNew and enter an EmployeeID that exists. You get a runtime error. The custom error message only shows after you close the Access error and try to close the form.
'Break on Unhandled Errors' is selected in the Tools>Options menu of the VBE.
Thanks in advance for your time and help. Have a good day!
The first text box on the form is for Employee ID. After update, it should be validated and if duplicate, show the custom error message. The Access message should not show at all. Can someone please have a look at this an help me understand where I am going wrong?
Here is what I have:
Code:
Option Compare Database
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Const conErrDuplicateKey = 3022
Select Case DataErr
Case conErrDuplicateKey
MsgBox "The Employee Number you entered already exists."
Response = acDataErrContinue
Case Else
' It's an unexpected error. Let Access handle it.
Response = acDataErrDisplay
End Select
End Sub
Private Sub cmdContinue_Click()
Dim rs As Object
Dim lngBookmark As String
'set a variable to the current record
lngBookmark = Me.EmployeeID
'open the new form
DoCmd.OpenForm "frmIndividualDataEdit"
'take it to the selected record
Set rs = Forms!frmIndividualDataEdit.RecordsetClone
rs.FindFirst "EmployeeID = '" & lngBookmark & "'"
Forms!frmIndividualDataEdit.Bookmark = rs.Bookmark
Set rs = Nothing
DoCmd.Close acForm, "frmAddNewJoin"
End Sub
Private Sub EmployeeID_AfterUpdate()
If Me.Dirty Then Me.Dirty = False
End Sub
'Break on Unhandled Errors' is selected in the Tools>Options menu of the VBE.
Thanks in advance for your time and help. Have a good day!