syntax for variables refering to objects

ScribeGuy

Registered User.
Local time
Tomorrow, 09:24
Joined
Mar 30, 2010
Messages
15
simple question yet I cannot find an example anywhere that works for me..

I want to refer to the following nested subform with a variable:

Forms!frmMain!frmMainSub1.Form!MainSub2.Form

(Sub2 lives inside Sub1, which lives inside Main)

my first thought was:

Dim strMainSub2 As String
strMainSub2 = "Forms!frmMain!frmMainSub1.Form!MainSub2.Form"

then I could use strMainSub2!MyControl = SomeParameter rather than the full long name.

Obviously this is not working for me. Could someone please tell me the correct syntax? Thanks so much.
 
There is no correct way and the syntax depends on where the code is executing.
Also, there is probably no need to create a variable.

Examples from Form frmMain: -

Code:
Private Sub cmdTestFromMainForm_Click()

    With Forms!frmMain!frmMainSub1.Form!MainSub2.Form
        .MyControl.BackColor = vbRed
        .MyOtherControl.BackColor = vbGreen
    End With
    
    [color=green]' Or[/color]
    
    With Me.frmMainSub1.Form.MainSub2.Form
        .MyControl.BackColor = vbYellow
        .MyOtherControl.BackColor = vbBlack
    End With

End Sub
 
Hey thanks ChrisO.

I had tried that method originally but got errors unless I used the full path name.

However in veiwing your code I see where I went wrong. I had neglected to put the dot (.) before each control after the With statement.

Thanks.
 

Users who are viewing this thread

Back
Top Bottom