Master save on a mdi parent

Posted on 2006-03-30
Last Modified: 2008-02-26
I have a mdi parent (frmParent) and a child (frmChild).  On the child is a tabcontrol with 2 tabs.  On each tab are datasets: tab1 has textboxes bound to ds1 and ds2; tab2 has textboxes bound to ds3 and ds4.

I have no problem with individual save buttons on each tab page to check for changes and then update the database.  My problem is using the Save on frmParent.  I want a "master" save button that will check for all the respective tab pages.

I know how to identify the active child form, e.g., Dim f as Form = me.ActiveMdiChild.  How do I identify programmically what datasets are associated with what tab page?  Somehow I need to cycle through each tab page, check whatever datasets are on it, and update as needed.

Can you help?
Question by:vlvawter
    LVL 34

    Expert Comment

    by:Brian Crowe
    dont' try and do the saving within the parent.  Just create a method in the child form that saves all the data on that form.

    class frmChild
    public sub SaveAll()
       'save changes
    end sub

    Author Comment

    Are you saying not to save inside the parent because it is too complicated or because it cannot be done?

    Also, if I create a control for frmChild that activates "Save All," is there a way to raise that event from frmParent?
    LVL 34

    Accepted Solution

    It's bad design.  One of the principles of object-oriented programming and design is encapsulation.  Members (variables) within a class should not be directly manipulated or accessed from outside the class.

    You don't need to add a control or raise event (although adding a delegate to take care of this is an option).  Just add the method to your childform.

    if typeof(me.activemdichild) is frmchild then
       ctype(me.activemdichild, frmchild).saveall
    end if

    You could also use reflection to determine if a given child has the "SaveAll" method.

    Author Comment

    I simply added a toolstrip on frmChild with a save icon.  The code behind that is a SaveAll.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now