Subform referencing

Kiwi-Wombat

Registered User.
Local time
Today, 02:03
Joined
Aug 2, 2004
Messages
56
An answer to a recent post gave me code to use when referencing a subform

forms!frmMain!subfrmMain.form!mycntrl.visible = false​
As part of this is used frequently for other fields I thought I could save code if I assigned it to a variable ie

Dim varsubName as String
varsubName = "forms!frmMain!subfrmMain.form!"

I then assumed I could put

varsubName & mycntrl.visible = false

but I get an error message

Compile error: Expected: expression​
It stops on the '&'

I assume that it can be done but I just can't see what the correct syntax should be

Any help would be gratefully received
 
in VBA,you can write the code like this:
with forms!frmMain!subfrmMain.form
!ctl1.visible=true
!ctl2.visible=false
...
end with
 
Thanks, I had forgotten about that however that only works if the lines follow each other.

I have a number of instances where the code is used in If statements etc so it doesn't appear to help. Assigning a variable is the obvious answer to shortening the code if it is possible
 
That makes more sense now.

I really appreciate your response

Thanks a million
 

Users who are viewing this thread

Back
Top Bottom