Which event do I choose when checking form against subform?

  • Thread starter Thread starter Mercy
  • Start date Start date
M

Mercy

Hey people :-)

This is a pretty basic question.

I have a FORM, which contains a SUBFORM. I want to be
able to check the data in the FORM against the data in
the SUBFORM. And if they don't match ... BEEP , MSGBOX ,
and force the user to enter the correct quantities by
CancelEvent. This is just so I can do a data validation
thingie.

The question is: Which event do I put this code in?

At first I put it in the "AfterUpdate" event for the
Form... but that was throwing an error before I even had
a chance to put data into the SUBFORM.

Right now I have the code in the "exit_subform" event.
But that forces me to return to the subform when the data
don't match. And that doesn't cover the case when the
error in data is in the Main form not the subform.

I am choosing the wrong event? Or am I choose the wrong
DoCmd? Maybe there's another more suitable DoCmd other
than "CancelEvent"?

Any help would be greatly appreciated! Thanks!

Mercy
 
It sounds to me that you should use the Form_BeforeUpdate Event of the
Subform (most validation checks should be done in Form_BeforeUpdate Event).
However, the Form/Subform combination may make things complicated.

If you still can't work it out, describe relevant Table structure (including
relevant relationship), the set-up of the Form / Subform and their
RecordSources as well as validation checks in details.
 
Mercy,

I agree with Van. And I disagree with your statement that it is a
"pretty basic question". :-) In fact, it is a very unusual situation
to have data "matching" in main form and subform, and needing to
validate this. In fact, I find it difficult to imagine a scenario
where this would apply. It could be, therefore, that your question
points to a table design problem, which we can advise on if you can
supply further information.

- Steve Schapel, Microsoft Access MVP
 
Back
Top