G
Guest
I have a data entry Form and after the user inputs the data I have a Save
button that the user will push to save and close the form. If the user
inputs duplicate data in the Primary Key Field Microsoft Access Will produce
it's own error message. I know the Error message number it is Run-time error
'3022', I was wondering if there is some kind of code I can put in so that if
this specific run-time error occurs I can put in my own Message Box. THis is
what I tried but it doesn't work....
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close acForm, "frm_DrawingControls_Add", acSaveNo
Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
If DataErr = 3022 Then
MsgBox("This record has a duplicate Id.", , "Message")
Resume Exit_cmdSave_Click
Else
MsgBox Err.Description
Resume Exit_cmdSave_Click
End If
End Sub
This obviously is wrong but is there code somewhat like this that will work?
button that the user will push to save and close the form. If the user
inputs duplicate data in the Primary Key Field Microsoft Access Will produce
it's own error message. I know the Error message number it is Run-time error
'3022', I was wondering if there is some kind of code I can put in so that if
this specific run-time error occurs I can put in my own Message Box. THis is
what I tried but it doesn't work....
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close acForm, "frm_DrawingControls_Add", acSaveNo
Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
If DataErr = 3022 Then
MsgBox("This record has a duplicate Id.", , "Message")
Resume Exit_cmdSave_Click
Else
MsgBox Err.Description
Resume Exit_cmdSave_Click
End If
End Sub
This obviously is wrong but is there code somewhat like this that will work?