error trapping

peterbowles

Registered User.
Local time
Today, 04:00
Joined
Oct 11, 2002
Messages
163
I am trying to trap an error and get rid of access built in error msgbox. I used this

On Error Resume Next
MsgBox "You need to enter a customer number"
Me.CustomerNo.SetFocus
Me.CustomerNo.Dropdown

in the Error event of the form, it works but still brings up the microsft error afterwards


any ideas
 
Post the whole procedure - that way we can see where it may be going wrong.

Describing the error would help too - Access has hundreds of possible trappable errors so to say "the microsoft error" isn't really clear.
 
sorry

the form is a customer sales order form.

main form has all the details about the customer
sub form has all the details of the order

if the user tries to do something with the sub form before they have entered a customer No on the main form

it says

"The MS Jet engine could not find the record in the table customers with the matching key fields Customer no"

so i tried to trap this error using the previous posted before in the on Error event of the form
 
Mile-O-Phile said:
Post the whole procedure - that way we can see where it may be going wrong.

Where does the database highlight within the code?
 
no part of the code is highlighted, just gives my error and then the MS error message
 
Try this:

Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
    Select Case DataErr
        Case Is = 3011
            MsgBox "You have not entered a customer number.", vbExclamation, "Missing Details"
            Me.CustomerNo.SetFocus
            Exit Sub
    End Select
End Sub
 
It still brings up the error

would it help if I posted the DB
 
Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 3011 Then

MsgBox "You have not entered a customer number.", vbExclamation, "Missing Details"
Response = acDataErrContinue
CustomerNo.SetFocus
Else
Response = acDataErrDisplay
End If


End Sub
 

Users who are viewing this thread

Back
Top Bottom