How to reference parent form from subform when parent name can be different

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • munkee
    Contributor
    • Feb 2010
    • 374

    How to reference parent form from subform when parent name can be different

    All,

    I want to reference a button on the parent form of a subform. The parent however could be two different form names.

    frmlog

    frmcorrective

    How do I check which form is loaded in order to create the reference to the correct parent? The parent will always be loaded at the time the subform is being used.

    I think the correct syntax for referencing a parent is along the lines of:

    Forms!frmlog!tg lchange.enabled = true

    Thanks for any help,

    Chris
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    I think something like this would work for you:

    Code:
    If me.Parent.SourceObject="frmLog" Then
       me.Parent.form.tglChange.Enabled=True
    elseif me.parent.sourceobject="frmCorrective" then
      'blah blah
    end IF

    Comment

    • munkee
      Contributor
      • Feb 2010
      • 374

      #3
      damnit! thats was so obvious why did I not even think.. thanks!


      Hmm for some reason it keeps only referencing frmlog when I load the code whilst using frmcorrective.

      Comment

      • TheSmileyCoder
        Recognized Expert Moderator Top Contributor
        • Dec 2009
        • 2322

        #4
        I believe, that subforms are loaded before main forms.
        I remember messing around with this at some point, and in the end i put alot of msgbox "frm_Thisfo rm opening", msgbox "frm_thisFo rm Loading" to try to determine the order of loading. I'd suggest trying that.

        Comment

        • munkee
          Contributor
          • Feb 2010
          • 374

          #5
          Couldnt get sourceobject working correctly but I managed with this:

          Code:
          If Me.Parent.Name = "frmlog" Then
              MsgBox "frmlog"
          ElseIf Me.Parent.Name = "Frmcorrective" Then
              MsgBox "frmcorrective"
          End If

          Comment

          • TheSmileyCoder
            Recognized Expert Moderator Top Contributor
            • Dec 2009
            • 2322

            #6
            Yes of course. I'm used to using it a bit the other way around, where im in the parent, and want to know which subform is currently displayed. The sourceobject is only used for a control containing a form.

            I believe you can choose your own reply as "best answer", so the thread gets marked as answered.

            Comment

            Working...