SharonInGeorgia
asked on
Access - Understaning DataErr
Please explain the logic when using DataErr from start to finish. Do you try to inclue all errors in the Form_Error section that might be encountered somewhere in the application or in a form? Where does the code reference or activate a specific DataErr such as the one listed below?
Private Sub Form_Error(DataErr As Integer, response As Integer)
response = acDataErrContinue
Select Case DataErr
Case 3022
MsgBox "Account Number already exist for this REGU."
Private Sub Form_Error(DataErr As Integer, response As Integer)
response = acDataErrContinue
Select Case DataErr
Case 3022
MsgBox "Account Number already exist for this REGU."
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So do I put the DataErr code in the Private Sub Form_Error for each form?
ASKER
Also, I'm getting the message "Record Saved' before I get the "Duplicate Error Message". Where do I need to put the error code to get the Duplicate message first?
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim response As vbmsgboxresult
If IsNull([GL Account]) Or [GL Account] = "" Then
MsgBox "Account Number Is A Required Field", vbCritical + vbOKOnly + vbDefaultButton1, "Missing Data"
Cancel = True
Exit Sub
Else
response = MsgBox("Do you want to save this Account Code", vbQuestion + vbYesNo, "Save Account Code")
If response = vbYes Then
MsgBox "Account Code has been added", vbOKOnly, "Account Added"
Else
MsgBox "This Account Code will not be saved", vbOKOnly, "Unsaved"
End If
End If
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim response As vbmsgboxresult
If IsNull([GL Account]) Or [GL Account] = "" Then
MsgBox "Account Number Is A Required Field", vbCritical + vbOKOnly + vbDefaultButton1, "Missing Data"
Cancel = True
Exit Sub
Else
response = MsgBox("Do you want to save this Account Code", vbQuestion + vbYesNo, "Save Account Code")
If response = vbYes Then
MsgBox "Account Code has been added", vbOKOnly, "Account Added"
Else
MsgBox "This Account Code will not be saved", vbOKOnly, "Unsaved"
End If
End If
End Sub
- Checking the value of DataErr against certain expected errors allows you to create custom error messages instaeac of having the user see the system generated messages. It also allows you to gracefully handle error consitions through code.
>Do you try to inclue all errors in the Form_Error section ...
Include those errors that are reasonable to expect in your code's execution, and include a Case Else to generically handle other errors.