Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2007

    Unanswered: Multiple subform instances of a form

    In my application I have a search interface controlled by a form called fsubFindTrainee. This form is displayed in a subform container in various parts of the program, and triggers the search interface. It leaves its output in a public local variable called Found.

    However my question is - if I access Form_fsubFindTrainee.Found, how do I know which instance of the subform I am accessing? And is there any way to access the other instances?


    I made a test application to test this phenomenom.

    Form1: Contains a subform container which displays Form2.
    Form2: Contains a public local integer variable Form_Form2.Val, and 4 buttons: "Load" (Opens Form3 as an acDialog), "Show Local" (MsgBox Val), "Set to 2" (Val = 2) and "Set to 3" (Val = 3).
    Form3: Contains a subform container which displays Form2, and a button "Show Global" (MsgBox Form_Form2.Val)

    So I clicked the buttons in this order: "Set to 2" on Form1, "Show Local" on Form1 (displayed 2), "Load" on Form1, "Show Global" on Form3 (displayed 0), "Set to 3" on Form3, "Show Global" on Form3 (displayed 3), "Show Local" on Form3 (displayed 3), {closed Form3}, "Show Local" on Form1 (displayed 2), "Load" on Form1, "Show Global" on Form3 (displayed 0 again).

    From this behaviour I deduce that if there is a subform containing an instance in the same form as the clicked button then it accesses that instance. This seems odd behaviour. Is there some documentation of this situation, or does anyone know what really goes on here?

  2. #2
    Join Date
    Dec 2004
    Madison, WI
    This would be interesting to see. Any chance you could upload a sample of it?
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Nov 2004
    If this search form of yours, is always implemented as a subform, then I'd refer through the forms collection in stead, i e

    Forms("frmTheMainForm").Controls("TheSubFormContro l").Form.TheProperty

    in stead of


    If the form isn't open, the latter will create an instance of the form, and bring back the uninitialized value of the public local (ZLS for string, 0 for numeric, 30/12/1899 for dates (essentially 0)), so this might create unexpected behaviour.

    I don't know if you can address specific subform instances, but my good old reference (Access 2000 Developer's Handbook, Sybex, Getz, Litwin, Gilbert p 547-557), has some good stuff on multiple instances of forms and pop ups, later editions probably also has such. How that plays with subforms, I don't know. You might have a look at Allen Brownes version which uses lot of the same approach (stuffing the form handle into a collection).

    Question remains if this is necessary, and whether my initial suggestion (referring through the forms collection) is sufficient.

Posting Permissions

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