Unanswered: Validate a subform on a tab control within a main form
I have a main form with a tab control on it which has several tab sections. The first 2 tab sections have data related to the main form & need to be completed before the remaining tab sections are enabled.
On the next 3 tab sections i have a subform on each of these.
What i need to do is to check that at least 1 record has been created in the subforms before the main record is saved. (i.e. If user enters data in main form only & tries to move to new record or exit screen i want an error msg stating that related records have not been created in the subforms).
So each main record created should have at least 1 record in the subform section.
I thought this check would be straightforward but it has become more complicated due to the structure of the tab control.
If i add the check to the Before_Update event on the main form then when i click on the subform tabs i get the error msg everytime & i can't move into the subforms to add the relevant record.
If i add the check in the subform Before_Update event then the event can be bypassed if no record is added in the subform.
I'm not sure where to add the code to do the check or what the code should be doing.
Does anyone have any idea on how to check a subform within a tab control has related records to the main form before the main record is saved?
The solution you suggested doesn't cover all angles in my problem.
I need the main form (parent form) to have the first data entry in order to create the record. The subforms are 1-to-many links to the parent form so the parent form must have the record created and validated first.
I then need the subforms (or the tables behind the subforms) checked to make sure the user has gone into them after creating the main record & added the subform records.
This is made more difficult as the subforms are in tab controls within the parent form so evrytime i try to run validation code in the main form & try to move to the subform tabs my validation error appears and i can't get into the subform to create the necessary records.
Do you know of a way around this or a solution that may help?
Main form (parent form) has the validation code within it in the Before_Update event. This contains validation for the parent form & a check to see if the required records have been entered within the subforms.
The subforms are located within a tab control in the parent form.
So when i complete the data entry in the parent form & try to move to the subforms in the tabs, the validation code obviously runs & notifies me that the subforms have no records entered (which is correct). But i can't go into the subforms to add the records.
I know why this code does not work as the order is incorrect (the parent form is checking the subform records before they have been entered) but i'm not sure where & how i need to run the validation check. The main record should not be created until all data is complete (or at least: the main record cannot be left or moved away from until the subform data is complete).
Ok, so you have to allow the main record to save before you can add subform records. What I would suggest is to remove record navigation etc so that the only way to add the main record is via the SAVE button (which you make) is clicked. The SAVE button does the validating and if all is ok, allows a Close or New action. While the SAVE button is available, the only other action should be a CANCEL button which will delete all the data entered... in essence turn your data entry form into a dialog box.
Another angle of attack you might want to try is to just allow navigation etc, but make the recordsource for the objects in a temporary table structure. When the user hits SAVE, the code validates and if it passes validation, copies the entries to the real table structure.