Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Jan 2001
    Location
    Brecon, South Wales, UK
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Subform reference to parent form procs & vars (97)

    I have a parent form with several subforms. I need code in my sub-form class modules to refer to variables defined in the parent form's class module. I assumed that as the parent form is, by definition, open this would be possible. But I can't find how to do it, short of defining public variables in a standard module.

    Also, I would like an event on the subform to invoke an event procedure on the parent form, but I can't find a way of referring to the latter. Me.Parent.Form_procedurename doesn't work. Is there a way of doing this?

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Subform reference to parent form procs & vars (97)

    You can't refer to variables from another form, even a subform, unless you've declared the variables as module level and public. That, in effect, turns them into properties of the form and you can then reference them as you would any other public property using Me.Parent.variablename.

    If you want to call a public routine on a parent form, you call it as a method of the form. So the syntax would be Me.Parent.Whatever.
    Charlotte

  3. #3
    Lounger
    Join Date
    Jan 2001
    Location
    Brecon, South Wales, UK
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Subform reference to parent form procs & vars (97)

    Charlotte
    Thanks: that solved my problem. The variables are still awkward as one is an array and it seems you can't declare an array public in a class module. But the procedure reference worked fine. What I had forgotten is that Access by default defines event procedures as Private, but you can change the declaration to public.

    I've been experimenting with a set of procedures to get Alt+hotkey combinations to work correctly on Access forms, especially to switch between the pages of a tab control. I need to be able to activate the hotkey procedures on the parent form even when the focus is in a subform. My procedures now work.

    Thanks a lot

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Subform reference to parent form procs & vars (97)

    If the array is single dimension, you might want to try a collection instead. Collections are very persistent, so even a global collection is pretty durable. Just be sure to remove all its elements before you close the database.
    Charlotte

Posting Permissions

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