Re: Where do I put the code main or subform?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Yes, Form_BeforeUpdate is the best solution for record-level validation that
is too complex to put into the table itself.

--
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:7D6EBCB7-2DCD-477B-ADAB-148DDBB01220@xxxxxxxxxxxxxxxx
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.)

"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.


.



Relevant Pages

  • Re: Access 2007 Technical Questions
    ... If your users are encountering Validation ... Rules being exercised when the control loses focus, ... developer is responsible for handling this with VBA code. ... and allows queries instead of cursors ...
    (microsoft.public.access.formscoding)
  • Re: Access 2007 Technical Questions
    ... it would be nice to be able to turn of validation. ... since we do have the before update event also (this is ... forcing the user to STAY on control, or use some quit button on the form! ... then you STILL MUST HAVE form's level validation code!!!. ...
    (microsoft.public.access.formscoding)
  • Re: Validation Rule on Table Field vs Form Control
    ... happens when you go from a main Form to the Form embedded in a Subform ... validation in VBA code in the AfterUpdate of Controls on the Form. ... they're trying to exit another control to get into a subform. ...
    (comp.databases.ms-access)
  • Re: Access 2007 Technical Questions
    ... When you state put a button on the form, do you mean a command button? ... validation rules as set in the events of that previous control, ... it doesn't matter which of the 2 validation events you put it ... in the validation rules as far as this point is concerned. ...
    (microsoft.public.access.formscoding)
  • Re: Validators in composite control firing prematurely
    ... and seems we can do some certain trick in our composite control's code. ... Then, we override our Custom Control's OnLoad method, there when postback, ... composite control. ... this approach need to disable clientside validation (since the ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)