Check Header Fields. (1 Viewer)

vagelisr

Registered User.
Local time
Today, 08:01
Joined
Apr 28, 2011
Messages
87
Hi to all.

I think that i have a very simple question......

I have a (header) form with 4 fields and a (detail) subform with 7 fields.
I want the user if he left any field in header form empty before fill any field in subform receive an error message and the empty field receive the focus.

Thanks and regards to all off you!!!!!!!!
 

vbaInet

AWF VIP
Local time
Today, 06:01
Joined
Jan 22, 2010
Messages
26,374
Test all the fields in the header form using the ENTER or GOT FOCUS event of the subform control. If the conditions are not meant, return the focus back to the header form.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:01
Joined
Feb 19, 2002
Messages
43,478
If the fields are required, then make them required at the table level. That way Access will not let focus leave the main form until all the fields are filled in or the update is cancelled (the escape key). Failing that, the code belongs in the main form's BeforeUpdate event. That is the most critical event in form processing. It is imperative that you understand when this event fires in order to control edits in your forms and to prevent saving "bad" data. If empty fields on the main form represent "bad" data, checking this condition in the subform is too late. The horse is out of the barn so to speak because the record has already been saved. You need to prevent the record from being saved by
1. using the database engine as I suggested earlier (best) OR
2. using the correct form event to trap errors which in any case that involves "empty" fields or a combination of multple fields is ALWAYS and ONLY the FORM's BeforeUpdate event.
 

Users who are viewing this thread

Top Bottom