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

Trapping Microsoft Access Errors Before the user sees them

Status
Not open for further replies.

mas5

Programmer
Dec 15, 2002
98
US
I have a data entry form for a table with a required field on each record. The required field is the last field in the data entry stream. When the user tabs through the field or enters I trap the error in the ON ERROR event of the form. I display a message noting the field is required and then clear the error. However, I can't seem to get the form to stop adding the record which results in an access error message. Is there any way I stop this attempted update from occurring and generating the error message?

Thanks.
 
In the BeforeUpdate event of the form, check to see if the field has a valid value. If not, issue a message and set Cancel=True.
 
Dear Mas5

Please read about my problem of "The DoMenuItem Action was...". Do you get same message after Cancel=true?

Rgds Purkka
 
Dear Purkka -

I don't get that message. I managed to trap it (error message is 2501). My solution is almost identical to the one in your thread.
 
Error trapping is an important tool. When I code, EVERY one of my procedures has error trapping, even the procedure only has one line calling some other procedure.

I have an article on the Error Trapping strategy I use up on my website, but the basic strategy is that every routine has all of this inside it:
Public Sub SubName()
'(c)Copyright 2/6/01 Jeremy Wallace
On Error GoTo Error

'Code Goes Here

Exit Sub

Error:
Select Case Err.Number
Case Else
Call ErrorTrap(Err.Number, Err.Description, "SubName")
End Select
End Sub

ErrorTrap is the name of a function that does a bunch of work with the error. Because I've already got the Select Case bit in there, it's easy for me to set up a new case to trap for any errors that come up with.

Jeremy =============
Jeremy Wallace
AlphaBet City Dataworks

Take a look at the Developers' section of the site for some helpful fundamentals.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top