dynamic sub-form

Posted on 2011-04-29
Medium Priority
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:João serras-pereira
  • 2
LVL 40

Expert Comment

ID: 35493263
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

by:João serras-pereira
ID: 35493408
What is a fixed set of variants? shall I define a number of forms and then a placeholder and then "show/hide"?
LVL 49

Accepted Solution

Dale Fye earned 2000 total points
ID: 35494022
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

by:João serras-pereira
ID: 35494127
gee thanks!!!!

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

850 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