choglad
choglad

Reputation: 23

Referencing a Subform's Subform Control in another Module MS Access VBA

Trying to reference a subform's subform control in VBA. I have a main form which, via buttons, opens up a subform. Within that subform are several buttons that open up another subform. Basically a Russian doll scenario with buttons.

The end goal is to have one function being called with the sub-subform's being used as a variable in a function called GetFile. The workaround right now is that I have different versions of the GetFile function in each sub-subform's VBA.

Here's the sub-subform's button click code:

Private Sub cmdButton_Click()
     Dim strForm As String

     strForm = Me.Name
     Call GetFile(strForm)
End Sub

Which then calls this module:

Function GetFile(strForm As String)

     Forms!frmMainMenu!subFrm.Form!subFrm!chkImport.Visible = True

End Function

Currently, I get this error: Runtime Error '2465'.

Upvotes: 0

Views: 4835

Answers (1)

Andre
Andre

Reputation: 27644

Refer to Form and Subform properties and controls

This is your case:

Forms!Mainform!Subform1.Form!Subform2.Form!ControlName.Enabled

so you probably want

Forms!frmMainMenu!subFrm.Form!subFrm.Form!chkImport.Visible = True

although your question is a bit confusing ("open a subform"? A subform is embedded in the parent form).


It may be easier to pass the form object instead of its name as parameter:

Call GetFile(Me)

then it doesn't matter where in the hierarchy the form is, simply use it directly:

Function GetFile(myForm As Form)

     myForm!chkImport.Visible = True

End Function

Upvotes: 1

Related Questions