Variable control names

  • Thread starter Thread starter TheGMan
  • Start date Start date
T

TheGMan

Guest
How do I refer to a form control using a variable?

1... FORM2 is opened by FORM1 (which stays active in the background)
2... In FORM2, the user makes a selection which defines the value for another control in FORM1. It may be any of 10 FORM1 controls, depending upon the user selection.
3... I'd like to have code that checks the user selection and builds the control name into a variable and then executes a standard routine for that variable.

Right now I have:
DoCmd.SelectObject acForm, "FORM1"
Forms![FORM1]![CustomerAttribute01] = "Some Value"

But I am referring to a specific control in FORM1.

I'm trying to achieve something like:
Dim vControlName as Field
vControlName = "CustomerAttribute01"
DoCmd.SelectObject acForm, "FORM1"
Forms![FORM1]!vControlName= "Some Value"

Which obviously isn't going to work.

Any help would be greatly appreciated!
Thanks
Gary
 
Forms(myFormVariable)(myControlVariable)
 
Sorry, I'm still a little confused...so bear with me.

If I define a variable:
Dim vControlName as Field

How do I set that variable to the actual control name AND set it's value?

vControlName = "CustomerAttribute01" (Does this define the control name?)
Forms!FORM1!vControlName = "Green" (Does this define the value of the control?)

Thanks again for any help...
Gary
 
Code:
Dim vControlName as [COLOR=Red]String[/COLOR]
vControlName = "CustomerAttribute01"
[COLOR=Red]Forms("FORM1")(vControlName)[/COLOR] = "Some Value"
 
That did it!!!!
This forum is such a great resource.
Thanks for all the help...
Gary
 

Users who are viewing this thread

Back
Top Bottom