Error Trapping Novice (1 Viewer)

Jordan76

Registered User.
Local time
Today, 08:02
Joined
Dec 26, 2002
Messages
49
Hi there,

Im using dlookup to search for values entered into 3 texts boxes.

When one of the values isnt found, I get a 2471 Error and have to push end to move along with the data entry.

What I want to do, but cant seem to do it is:

I want the error to generate my own message box, then when the user hits OK i want to setfocus to the next entry box.

I cant figure out how to have the message box pop up on the error.

I found the help files difficult to understand. Could you please give me an example of trapping the error? Also would I put the error handling everyplace I use the Dlookup function that is causeing the error?


Thanks in advance,
Jordan
 

Mile-O

Back once again...
Local time
Today, 08:02
Joined
Dec 10, 2002
Messages
11,316
Code:
Private Sub YourProcedure_it's event()

On Error Goto Err_ErrorTrapping

   ' the control's code goes here

Exit_ErrorTrapping:
   Exit Sub ' let's the routine know it has come to it's end

Err_ErrorTrapping:
   MsgBox "An error has occurred."
   Resume Exit_ErrorTrapping

End Sub

In the Err_ErrorTrapping: section you can put any code you wish to check the error number, set focus, etc

The Resume tells the error handler where to go once the trapping is over.

Sorry, I can't post more it's almost 17:00 and I'm out of here.
 

Jordan76

Registered User.
Local time
Today, 08:02
Joined
Dec 26, 2002
Messages
49
Thats Fantastic thank you, I just needed to know where to put it.
Do I need to specifiy any error? like its generating a 2471, do i need to say 2471 anywhere?
 

Mile-O

Back once again...
Local time
Today, 08:02
Joined
Dec 10, 2002
Messages
11,316
You can say:

Code:
Select Case Err.Number
   Case Is = 3
   Case Is = 2471
   Case Else
      MsgBox "Unknown Error", vbExclamation
End Select

and deal with the different errors that may arise.
 

Users who are viewing this thread

Top Bottom