Check subform fields for data

  • Thread starter Thread starter Jeff Klein
  • Start date Start date
J

Jeff Klein

I want to create code that will check certain fields to make sure they have
data. Easy enough......but, My form has a subform that might have 2 or 3
records within it. I want to make sure the subforms records are complete.
What is the process to make a check in the main forms "close" button that
looks at the subform records?
 
The record is saved in each form individually.

You must complete the main form record (and save it) before you can create
the subform record. Then each record in the subform is saved before you can
create the next one. That means you cannot require the subform records to be
complete before you allow the main form record to be saved.

If you have some fields that should always have a value, open the table in
design view, and set the Required property of the field to Yes (lower pane
in table design).

If you want a more complex validation before allowing the record to be
saved, use the BeforeUpdate event of the form (not control). Note that the
subform has its own BeforeUpdate event.

If you did want to run some kind of validation in the Close event of the
main form, how would you determine which record to check? Could it be a
previous record, e.g. if the user has moved to another new record when they
close the form? Could they be editing an old record? Deleting a record?
Deleting subform records? The possible sequence of events is probably too
unpredictable to use Form_Unload for any kind of validation, not to mention
that the data is already committed.
 
Back
Top