Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2006
    Posts
    30

    Exclamation Unanswered: Validate a subform on a tab control within a main form

    Hi guys,

    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?

    Any help would be appreciated.

    Thank you,

    Shuja

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10

  3. #3
    Join Date
    Sep 2006
    Posts
    30
    Hi georgev,

    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?

    Regards,

    Shuja.

  4. #4
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    I don't understand why your validation error message stops you from entering a subform. When is the code run and what is it doing?
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  5. #5
    Join Date
    Sep 2006
    Posts
    30

    Exclamation

    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).

    I hope that makes sense? Please help.

    Regards,

    Shuja

  6. #6
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    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.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •