Link to home
Start Free TrialLog in
Avatar of SharonInGeorgia
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."
Avatar of mbizup
mbizup
Flag of Kazakhstan image

- DataErr is the error code returned if an error occurs in your form.  
- 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.

ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SharonInGeorgia
SharonInGeorgia

ASKER

So do I put the DataErr code in the  Private Sub Form_Error for each form?  
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