I have customised a form to display my own error messages using:-
Private Sub Form_Error(Data Err As Integer, Response As Integer)
' If an error occurs because of duplicate data in a required field
' Display own custom error message
Const conErrDuplicate Key = 3022
Const conErrZeroKey = 3058
Select Case DataErr
Case conErrDuplicate Key
MsgBox "This Serial Number already exsists: " & Search, , "Warning Duplicate Record!"
Response = acDataErrContin ue
Case conErrZeroKey
MsgBox "You Must Enter a Serial Number before you Save the Record: " & Search, , "Warning No Serial Number!"
Response = acDataErrContin ue
Case Else
'Display a standard error message
Response = acDataErrDispla y
End Select
End Sub
In order to get my "Save" command button (not changed from Command26) to do the same i used:-
Private Sub Command26_Click ()
On Error GoTo Err_Command26_C lick
DoCmd.DoMenuIte m acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Me.[Serial Number].SetFocus
Me.Command26.Vi sible = False
Exit_Command26_ Click:
Exit Sub
Err_Command26_C lick:
If Err = 3022 Then
MsgBox "This Serial Number already exsists: " & mSearch, , "Warning Duplicate Record!"
Else
' Display the error number and the generic Access message.
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_Command26_ Click
End Sub
But this only works for the one error code. Is there a way to get my "Save" command button to work with multiple error codes like my form?
PS. my programming skills are very basic at best, the above has been copied and adapted from info found on the net.
Regards
Ezzz
Private Sub Form_Error(Data Err As Integer, Response As Integer)
' If an error occurs because of duplicate data in a required field
' Display own custom error message
Const conErrDuplicate Key = 3022
Const conErrZeroKey = 3058
Select Case DataErr
Case conErrDuplicate Key
MsgBox "This Serial Number already exsists: " & Search, , "Warning Duplicate Record!"
Response = acDataErrContin ue
Case conErrZeroKey
MsgBox "You Must Enter a Serial Number before you Save the Record: " & Search, , "Warning No Serial Number!"
Response = acDataErrContin ue
Case Else
'Display a standard error message
Response = acDataErrDispla y
End Select
End Sub
In order to get my "Save" command button (not changed from Command26) to do the same i used:-
Private Sub Command26_Click ()
On Error GoTo Err_Command26_C lick
DoCmd.DoMenuIte m acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Me.[Serial Number].SetFocus
Me.Command26.Vi sible = False
Exit_Command26_ Click:
Exit Sub
Err_Command26_C lick:
If Err = 3022 Then
MsgBox "This Serial Number already exsists: " & mSearch, , "Warning Duplicate Record!"
Else
' Display the error number and the generic Access message.
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_Command26_ Click
End Sub
But this only works for the one error code. Is there a way to get my "Save" command button to work with multiple error codes like my form?
PS. my programming skills are very basic at best, the above has been copied and adapted from info found on the net.
Regards
Ezzz
Comment