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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error trapping on data entry to form

Status
Not open for further replies.

frantik

Technical User
Nov 9, 2002
93
GB
I am trying to trap errors when users enter data from a form

I have a field - project number - where if they enter a non valid number they get a MS Access error message - MS Jet enging cannot find matching error etc.

they only get this error when they tab out of this field. When they click out of the field this does not occur.

Quesiton 1 - Why does this error not appear when they click out?

Question 2: I have used:

private Sub Combo116_Exit(Cancel As Integer)
On Error GoTo errorhandler

exithere:
Exit Sub
errorhandler:

Select Case Err.Number

Case 3101
MsgBox "Please enter a valid Project Number"
Resume exithere
Case Else
Resume exithere
End Select

End Sub

To try and trap the error but I still get the standard MS error message - Can anyone tell me where I am going wrong please????

Thanx.
 
I would always try to
Code:
resume next
when error trapping but report the error (nicely formated).

You may be getting more than one error but only the first is reported.

I try to include 2 levels of error catching on EVERY sub with dodgy code. Thus if the sub gets more than two errors it stops and the next on error is called in the sub that called the buggy sub.

Code:
Private sub test()
On error goto err1


exit
err2:
msgbox "error 2 on sub(test): " & Err.Number & ": " & err.Description
resume next

err1:
On error goto err2
msgbox "error 1 on sub(test): " & Err.Number & ": " & err.Description
resume next

end sub

This may provide more insight.

help any? -Matt
 
Hi Matt

That is a really useful tip and I will be using it - but unfortunately it is not working here - I think I must be putting the code in the wrong place.

I enter data on a form, if I miss out a key field it comes up with the error when I click on the second page of the subform.

where should I try and trap the error - I have put it in a number of places (latest since it occurs when I click on the second page - I have put it under on Click for that page!)

No Joy!!! Help!!!

thanks
 
When you are troubleshooting a problem don't exit the subroutine until you figure out what is happening.

Select Case Err.Number

Case 3101
MsgBox "Please enter a valid Project Number"
Resume exithere
Case Else
> Resume exithere
End Select
>> Resume
End Sub

Place a breakpoint at the indicated > spot. When it traps place the cursor on the >> spot and enter Ctrl+Alt+F9. This will move the processing to the resume where you can press F8 to take a single step which will move you to the exact line that is causing you a problem. Here's where your work starts. Use the immediate window to enter the line of code an make changes to try to prevent the error.

Also, after it initially traps enter ?Err.Number in the immediate window to find out why it isn't trapping on your code. I assume it will give you an error number that is NOT 3101.
-------------------------------------
scking@arinc.com
Try to resolve problems independently
Then seek help among peers or experts
But TEST recommended solutions
-------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top