I am trying to create a custom error message. I am getting a very odd responce. 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?
Thanks in advance for your time and help. Have a good day!
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