Forms! syntax question

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

In making reference/settings to a text-box field in another form,
I've used the statement:

Forms![TMS Switchboard].Form!InstName.Caption = IPName

Where "TMS Switchboard" is the name of the form. What's the
syntax if the name of the form is contained in a string variable?

Like:
Dim strSwBrdName as String
strSwBrdName = "TMS Switchboard"

I tried the substitution

Forms![strSwBrdName].Form!InstName.Caption = IPName

but that's not it.

Thanks,
Bill
 
In making reference/settings to a text-box field in another form,
I've used the statement:

Forms![TMS Switchboard].Form!InstName.Caption = IPName

Well, first off, the .Form! is not necessary if InstName is a control
on the form named TMS Switchboard. It's needed (and maybe not
absolutely then) when you're referring to a form object within a
Subform control, but - though it's evidently legal here - it's not
needed.
Where "TMS Switchboard" is the name of the form. What's the
syntax if the name of the form is contained in a string variable?

Like:
Dim strSwBrdName as String
strSwBrdName = "TMS Switchboard"

I tried the substitution

Forms![strSwBrdName].Form!InstName.Caption = IPName

but that's not it.

Very close! You can use *three* different syntaxes for referring to
the members of a collection: the sequential number in parentheses (not
much use here since the Forms collection gets renumbered every time a
form is opened), its name in brackets with a ! delimiter, and its name
in parentheses: try

Forms(strSwBrdName)!InstName.Caption = ...

John W. Vinson[MVP]
 
John,
Forms(strSwBrdName)!InstName.Caption = ...
is perfect.
Thanks,
Bill
===================================================
John Vinson said:
In making reference/settings to a text-box field in another form,
I've used the statement:

Forms![TMS Switchboard].Form!InstName.Caption = IPName

Well, first off, the .Form! is not necessary if InstName is a control
on the form named TMS Switchboard. It's needed (and maybe not
absolutely then) when you're referring to a form object within a
Subform control, but - though it's evidently legal here - it's not
needed.
Where "TMS Switchboard" is the name of the form. What's the
syntax if the name of the form is contained in a string variable?

Like:
Dim strSwBrdName as String
strSwBrdName = "TMS Switchboard"

I tried the substitution

Forms![strSwBrdName].Form!InstName.Caption = IPName

but that's not it.

Very close! You can use *three* different syntaxes for referring to
the members of a collection: the sequential number in parentheses (not
much use here since the Forms collection gets renumbered every time a
form is opened), its name in brackets with a ! delimiter, and its name
in parentheses: try

Forms(strSwBrdName)!InstName.Caption = ...

John W. Vinson[MVP]
 
Back
Top