Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Require a subform entry before update of Main form

Status
Not open for further replies.

Prattdakota

Vendor
Jan 10, 2003
38
US
I have a form which has a subform. The subform displays reasons relating to the main form record. I have a combo box on the subform (cboReasonCode) which allows the user to pick the reasons. All I would like to do is require that at least one reason be entered before moving to the next record or a new record. I can't seem to use the before_update or even after_update events to check because they are executed when I move to the subform to pick a reason, thus displaying my message "You must pick a reason".

I'm out of ideas. Any help would be appreciated.
 
When you say 'moving to the next record or to a new record', are you referring to the subform or the main form?

You may want to use the before update function of the Subform rather than the before update function of the Main form.

Another way might be to put Is Not Null as the data validation rule in the field which is the control source for the combo in the sub form.
 
Thanks for your input beetee. Sorry for the ambiguity. I want to make sure a reason is selected when I go off the current record of the main form.

Before posting I tried putting Is Not Null in the validation property of the cboReasonCode control. It did not work. I also just tried putting code in the before_update event of the subform as you suggested. Unfortunately, it did not work because the user is not forced to go to the subform. Therefore, the control validation is not invoked and the before_update event does not take place.

My thinking right now is that I may have to have a verify button on the main form, which will check for a reason before letting the user proceed. Seems like there should be a better option, but I haven't figured it out.
 
Perhaps a two-pronged approach is called for:

1) put the validation code in the table, not the subform
2) in the form before_update, verify that there is at least one record in the subform.

other than that, I'd probably be doing what you're doing, trial and error. Good Luck!
 
beetee, thanks very much for your thoughts on this problem. I'm not sure what "put the validation code in the table, not the subform" means. Do you mean on the main form? That may have to be the solution.

Again, thanks, I appreciate your help and that of the other experts in this forum.
 
Always glad to add confusion to the topic.

If you look at a table in design view, you may notice that you can enter validation rules for fields. The validation rules are not as sophisticated as those you can use in forms; but in this case, since we are only checking for a valid value, the 'is not null' should suffice.

but, on reflection, the behavior of having validation code in the subform or in the table should be the same. But, when things go wrong, sometimes you have to play around a bit.
 
I gave your last suggestion a try to no avail. I believe I will try the following: disable the navigation keys; add "new record", "next" and "previous" buttons to the main form; code the OnClick event in the buttons to check the subform for data.

I'll post the results when I discover that it does or does not work. Sincerely, thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top