using variable in qualified form name

  • Thread starter Thread starter lynn
  • Start date Start date
L

lynn

Hi,
Is it possible to do something like this:

dim sformName as string
sFormname = "OtherForm"

And then refer the form control

forms!OtherForm.txtBox1

as

forms!sFormName!txtBox1

If so what is the correct syntax?

Thanks
 
you can't use a string variable; use a form variable, as

Dim fWhatever As Form
fWhatever = Forms!FormName

fWhatever.txtBox1

the system will recognize variable fWhatever as the
specific form object you assign to it.

hth
 
Hi Lynn !

You are allmost there but try this

Dim sformName as string ' thats okay
sformName = "Otherform" ' okay

now

Forms(sformName)!txtbox1.text = "something"

hope you can use it

John
 
lynn said:
Is it possible to do something like this:

dim sformName as string
sFormname = "OtherForm"

And then refer the form control

forms!OtherForm.txtBox1

as

forms!sFormName!txtBox1

If so what is the correct syntax?

Use this syntax:

Forms(sFormname)!txtBox1
 
Hey John, your VB is showing ;-)
In Access VBA drop the Text property and use Value instead.
It's the default property so you don't have to specify it if
you don't want to. (Note: the Text property is only useful
while the control is being edited)
 
Back
Top