Set variable for nested subform?

geoB

Registered User.
Local time
Today, 10:30
Joined
Oct 10, 2008
Messages
68
I am not sufficiently fluent in vba so I flop around, experimenting with naming conventions to get references to controls correct. I eventually get it right, but this consumes a lot of time. It would be nice to have a function that would return the proper reference for me.

Plus, I've noticed that the syntax for referencing a control explicitly is not the same as setting a variable for the form then referring to the form!control. An example:

I have a form frmMomsBabies, with a subform control ctlSubbabies. The fully qualified identifier for the control txtBaby on the subform is forms!frmMomsBabies!ctlSubbabies.form!txtBaby. However, if I dimension frmBaby as a subform, it must be set = forms!frmMomsBabies!ctlSubbabies so that I can reference frmBaby!txtBaby. The difference is that ".form" does not appear in the set statement.

I'm flummoxed now trying to set a variable for a nested subform. And all of the usual suspects don't seem to work. So I'm hoping someone else has solved this problem and can point me in the right direction. Is there a function that will report the fully qualified name of any reference?

Thanks for reading.

George
 
Last edited:
Be aware that a Form object and a SubForm object are not the same thing.
Code:
Dim frm As Form       [COLOR="Green"]'this is a form[/COLOR]
Dim sfm As SubForm    [COLOR="Green"]'this is a control on a form that might host a form[/COLOR]
Dim tb as TextBox
[COLOR="Green"]'these are valid assignments[/COLOR]
set sfm = me.ctlSubform
set frm = sfm.Form
set frm = me.ctlSubform.form
set tb = me.ctlSubform.Form.ctlTextBox
I never use the '!' character in object references.
Code:
set tb = Forms("frmMomsBabies").ctlSubBabies.Form.txtBaby
 

Users who are viewing this thread

Back
Top Bottom