Validate parent fields when creating subform record

  • Thread starter Thread starter P
  • Start date Start date
P

P

I'm working on a system which has subforms containing order details, and
parent forms containing company details.

Some of the information for a company is mandatory - e.g. we must have a
company name and a country. I want to add some validation so that a subform
record cannot be created unless the mandatory fields contain content.

Where is the best place to do this validation? I've tried OnCurrent, OnOpen
and OnLoad for the subform, but they don't give me the Cancel parameter -
perhaps I'm totally off-base on it.

Regards,

Pete
 
Presumably you have a main form bound to the Order table, with a subform
bound to the OrderDetails table (as in the Northwind sample database.)

If so, Access will save the main form record before you move into the
subform. You can therefore validate the main form record in its BeforeUpdate
event (i.e. Form_BeforeUpdate.) The user will not be able to move the focus
into the subform until the main form record is completed satisfactorily.

For an even easier approach, open the Orders table in design view, and set
the Required property of your Company and Country fields to Yes. Save. That
takes care of it without any code.
 
Back
Top