Share via

Reference a subform within a subform

Anonymous
2010-08-05T19:17:45+00:00

I would like to reference a subform within a subform from my main form's OnCurrent event procedure.  I've seen some threads on this but still can't seem to make this work. Any direction would be helpful.

Main Form: frmMain

1st Subform in frmMain: sbfrmPrimary

2nd Subform in sbfrmPrimary: sbfrmSecon

Here is the code that isn't working. VBA highlights ".sbfrmSecon".

If Me.sbfrmSecon.Controls("TxtOne") = 1 Then

  Me.TextFour.Visible = True

     Else...

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

7 answers

Sort by: Most helpful
  1. Anonymous
    2010-08-06T16:40:31+00:00

    Which error?  it's difficult to discuss an error without knowing what error occured

    Where is sbfrmThird located?  If it is in the main form then I would expect it to work as long as sbfrmThird is the name of the subform  control that displays a form object.   If it is a subform of another subform, then you have to go through both subform controls as in the If line.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-08-06T16:28:45+00:00

    Marshall,

    I think that I am grasping this concept but a point still seems to be escaping me.

    In my above example, you correctly suggested using the names of the two sub forms (as a path) to dive down to this subform control name of TxtOne which allowed the next line (me.TextFour.Visible=True) and subsequent others to work perfectly.  However, if I use this same logic to reference other text boxes in a different subform(s) then errors occur.

    For example:  

     If Me.sbfrmPrimary.Form.sbfrmSecon.Form.TxtOne = 1 Then

        Me.sbfrmThird.Form.TxtState.visible=true     ... (error)

    It seems that I am using the same logic to alter my text box TxtState yet VBA will not allow me to do this.  Can you give me your thoughts?

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-08-05T19:44:35+00:00

    I spent alot of time trying various syntax versions.  Thank you both for your assistance.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-08-05T19:36:42+00:00

    If (Forms!frmMain![sbfrmPrimary].Form![sbfrmSecon].Form!TxTOne = 1 ) Then

    Me.TextFour.Visible = True

    Else

    Note this is the full path to show you this, normally you would use Me.***** 

    So you would not need to use Forms!frmMain as your are referencing from this so your Me.  would show just the sub and the 2nd sub

    But I thought you'd like to see how it works

    Enjoy

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2010-08-05T19:36:30+00:00

    Try using:

       If Me.sbfrmPrimary.Form.sbfrmSecon.Form.TxtOne = 1 Then

    But it is not using the name of the form objects that are used as subforms.  Instead, you must use the names of the subformcontrols that display those form objects.  The name of a subform control may or may not be the same as the form object it displays.

    Was this answer helpful?

    0 comments No comments