Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Handler resume

Status
Not open for further replies.

balistikb

Technical User
Nov 12, 2002
177
0
0
US
How can I have the error handler resume to a certaine spot of code?
 
well this is what it does.. It bypasses my error message and continues to yours. Eventhough it is the error number 3421. But either way, it doesn't pop the prompt back up for the user to try again.
 
The if statement in your error handler is wrong.

Cange it from: If Error = 3421 Then

To:If Err.Number = 3421 Then

Thern add the label and the resume back as below.

Public Sub NoMatch()

On Error GoTo ErrorHandler
ContinueHere:
prompt$ = "Please enter class number."
SearchStr$ = InputBox(prompt$, "CLASS NUMBER")

Do
datClassEval.Recordset.Index = "PrimaryKey"
datClassEval.Recordset.Seek "=", SearchStr$

Loop While datClassEval.Recordset.NoMatch

txtLocator.Text = datClassEval.Recordset![LocNumber]
txtName.Text = datClassEval.Recordset![CLASS_NAME]
txtTrainer.Text = datClassEval.Recordset![REGISTRAR_INSTRUCTOR]
txtDate.Text = datClassEval.Recordset![Date]
txtHours.Text = datClassEval.Recordset![CLASS_HOURS]
Exit Sub
ErrorHandler:
If Err.Number = 3421 Then
MsgBox "Please enter correct value", vbCritical
Resume ContinueHere
else
msgbox err.number & ": " & err.description 'Catch other errors
End If
Thanks and Good Luck!

zemp
 
It works like a charm...
THANK YOU
Now how could I give the cancel button on that prompt to cancel and close the form?
 
I don't believe that the inputbox function allows you to react to buttom clicks like the msgbox function does. You may have to place a cancel button on the form itself.

You can also check the SearchStr$ after the input box function and if it ="" then you can exit and close the form. Just a thought. Thanks and Good Luck!

zemp
 
Should I change the prompt to a message box? I would really like the user to exit out if they must. BEcause as it stands now, they enter a correct number it allows them to get to the form. If they enter a wrong number it gevver them the error and lets them try again. If they put nothing then it keeps prompting for a number. But what if they opened the form by mistake? The prompt opens up and then they have no way to exit.
 
By changing to a msgbox function you will lose the ability to retrieve user input. So that may not be what you want.

What I would do is to add a text box on the form that allows the user to enter the class number. Until a valid number is entered the rest of the form is disabled. This forces the user to enter a number. If want to exit the form you can have a close or cancel button right on the form that will close it. This will also remove the need for the input box. You will also need to add a find button that they can click to find the class.

This also gives you the opportunity to use the text boxes .keydown event to ensure that only numbers are entered by not allowing anything else.

This way if no record is found the user just enters a new value and clicks the find button again.

Another option would be to create a form that acts and looks like an input box and then you could deal with the click event of a cancel button. This however will require the passing of variables from one form to another or global variables. Thanks and Good Luck!

zemp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top