Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Jan 2003
    Location
    Pembroke Pines, Florida, USA
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Determining name of parent form (Access 2002 SP1)

    Hi all,

    First off, thank ye much for all the recent help. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Now, the new question of the day is:

    I have a child form which is called from 2 different parent forms. Based on which parent form called it, I have an IF condition set up for the child form's On Load event. What I need is to have a way for the child form to determine which parent form called it, and act accordingly from that point.

    Any suggestions?

    [Edit]
    I thought that perhaps I should declare a static variable and populate it with the name of the form as needed. Would this be a viable solution? Or is there a cleaner and more elegant solution to use?

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determining name of parent form (Access 2002 SP1)

    If you are using

    DoCmd.OpenForm "Form2"

    to open the form, there is a OpenArgs paraemter that you can use to pass the name form that is opening the second form.

    DoCmd.OpenForm FormName:="Form3", OpenArgs:=Me.Name

    Then in the OnLoad event of the second form, you can do something like this:

    If Me.OpenArgs = "Form1" then
    'Do code specific to when openend from the First Form
    ElseIf me.OpenArgs = "Form2" then
    'Do code specific to when openend from the Second Form
    Else
    'This for was opened from somewhere else
    End If
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  3. #3
    New Lounger
    Join Date
    Jan 2003
    Location
    Pembroke Pines, Florida, USA
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determining name of parent form (Access 2002 SP1)

    Bryan,

    That would have worked wonderfully. Unfortunately, I failed to mention one important tidbit of information (sorry!) - both main forms have the same subform within it, and the subform calls the child form. What I need is to pass the name of the main form, through the subform, and onto the child form.

    Since the subform isn't opened with DoCmd.OpenForm, is there a way to modify what you listed to cover this scenario?

  4. #4
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determining name of parent form (Access 2002 SP1)

    Well, in that case,

    Me.Parent.Name will give you the name of a subform's Parent.

    So instead of

    DoCmd.OpenForm FormName:="Form3", OpenArgs:=Me.Name

    Use

    DoCmd.OpenForm FormName:="Form3", OpenArgs:=Me.Parent.Name

    and then use the same code in the OnLoad event of Form3.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

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

    Re: Determining name of parent form (Access 2002 SP1)

    You don't actually have to use Me.Parent.Name when you reference the parent form. Just Parent.Name works fine.
    Charlotte

  6. #6
    New Lounger
    Join Date
    Jan 2003
    Location
    Pembroke Pines, Florida, USA
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determining name of parent form (Access 2002 SP1)

    Worked beautifully!

    Thanks much.

Posting Permissions

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