dynamic sub-form

Posted on 2011-04-29
Last Modified: 2012-05-11
depending on the value of a field [CodeDoc] on a main form, I want to present a specific (and different on each case) sub-form, using different master/child fields. Ideally, some properties eg. Height and Width should also be dynamically set.
How do I do it?
Question by:jirdeaid
    LVL 39

    Expert Comment

    Yf you have fixed set of variants, you can create many subforms on same place and make visible only one, depending from your choice.

    Author Comment

    What is a fixed set of variants? shall I define a number of forms and then a placeholder and then "show/hide"?
    LVL 47

    Accepted Solution

    You would use the Form_Current event, something like:

    Private Sub Form_Current

        Select Case me.txt_CodeDoc
            Case "A"
                me.subformcontrolname.SourceObject = "frm_subformA"
                me.subformcontrolname.LinkMasterFields = "FieldA"
                me.subformcontrolname.LinkChildFields = "FieldA"
            Case "B"
                me.subformcontrolname.SourceObject = "frm_subformB"
                me.subformcontrolname.LinkMasterFields = "FieldB"
                me.subformcontrolname.LinkChildFields = "FieldB"
           Case Else
                me.subformcontrolname.SourceObject = "frm_subformElse"
                me.subformcontrolname.LinkMasterFields = "FieldID"
                me.subformcontrolname.LinkChildFields = "FieldID"
       End Select

    End Sub

    You could insert other lines in here to change the width and height of the subform if you wanted to.

    Author Closing Comment

    gee thanks!!!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
    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…

    759 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

    13 Experts available now in Live!

    Get 1:1 Help Now