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

Error source

Status
Not open for further replies.

Chad1984

Technical User
Joined
Jul 10, 2007
Messages
35
Location
US
I've read a little bit about error trapping/handling in Microsoft Access, but it's still confusing to me.

According to the client's business rules, the user must be prevented from accessing the various subforms until all required fields are filled in on the main form. I would like a specific error message displayed (for example, "please fill in the street address"), and then for the focus to be set to that field. If the user enters a field and tries to leave without entering a value, or after removing the existing value, I want the focus to be left there and a specific error message printed.

My problem is that I don't know where the error is coming from. I cannot rely on the value of the field- if the user clears out the value, the VB code only sees the last valid value, not "". After reading up, it looked like Err.Source was the answer, that I could slip this into my MsgBox and as the DoCmd.GoToControl parameter; but in the Form_Error function, these are both blank when I try to access them! Any ideas?
 
If you set a Validation rule, say:

[tt]<>"" And Is Not Null[/tt]

You will get a Form_Error if the rule is violated. You can check the Text property of a control to check the current value of a control, rather than the saved value.
 
Well, I do have validation rules set... so I ended up checking the .Text property in the BeforeUpdate event of every required field, popping up a MsgBox and setting Cancel=1 if necessary. So it worked, thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top