Re: Where do I put the code main or subform?
- From: Tim <Tim@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 20 Oct 2006 13:00:01 -0700
OK...Here is my scenario. I have a main form and a subform. The main form is
used to display the record, say, student records (name, adress, etc.), that
pull out from a table. The subform is used to display their scores entered
by teacher(s). I would like to validate what a teacher enter, i.e., the field
must not be blank or empty before s/he can go to the next textbox. The
teacher would click on the navigator of the form at the bottom to advance to
the next student record.
My question is if it's appropriate to use Form_BeforeUpdate?
Thank you, tim
"Tim" wrote:
Thank you very much, experts. It's interesting, isn't it? Actually, I think.
my forms (main and subform) are probably different. I will take a look at my
forms again and let you guys know what I think.
Thanks -- tim
"Allen Browne" wrote:
I don't find the Exit event of the controls useful:
a) It does nothing positive: it never fires if the user never visits a
control (e.g. if the user skips a control by clicking in another one).
b) It is unnecessarily restrictive. For example, if you have a control (such
as the city) that automatically assigns a value to another control (such as
the zip code), and the user clicks in the zip code before filling out the
city, you now have them stuck there until they go and look up the zip code
for themselves somewhere.
As Rick says, even if this subform's RecordSource is a query, the query
still gets its fields from tables, so you can still set the Required
property of the field(s) in the table(s).
In general, Form_BeforeUpdate is the best place to do record-level
validation, including:
- validation that is too complex to use in a field's Validation Rule;
- optional validation (i.e. warn the user, but allow the entry anyway);
- comparisons between fields (since you need both fields filled in before
you can make the comparison.)
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Tim" <Tim@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C51850DC-B8EE-47E4-95BE-8D37AC8BE1D4@xxxxxxxxxxxxxxxx
Hi Allen,
Thank you for your help. Now, it's clear that I need to put my VBA codes
into the Subform's BeforeUpdate event. How about the Exit event in the
subform for every textbox? Maybe I don't need it, do I?
I can not use the Required property because the record source of this
subform is a query not a table.
Thank you. I appreciate your help. tim
Tim, use the BeforeUpdate event of the *form*, not the controls. And it
must
be in the subform's module.
Even simpler, open your table in design view, and set the Required
property
to Yes for the fields where a value must be entered. Then Access won't
allow
the record to be saved unless the required fields have a value--no code
needed.
- Follow-Ups:
- Re: Where do I put the code main or subform?
- From: Allen Browne
- Re: Where do I put the code main or subform?
- References:
- Re: Where do I put the code main or subform?
- From: Allen Browne
- Re: Where do I put the code main or subform?
- From: Allen Browne
- Re: Where do I put the code main or subform?
- Prev by Date: RE: 2 List Boxs - Multiple Select - select from single box
- Next by Date: Re: Union to populate cbo2 based on cbo1
- Previous by thread: Re: Where do I put the code main or subform?
- Next by thread: Re: Where do I put the code main or subform?
- Index(es):
Relevant Pages
|