Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing Control with a variable

Status
Not open for further replies.

Maquis

Programmer
Jul 19, 2001
934
US
Hi there. I'm sure this question has been answered before, but I tried doing a keyword search in all the Access forums and I couldn't find an answer.

I need to be able to reference a control on a form/report by using a variable. How do I do that? What is the correct syntax?

Here's some pseudocode for what I'm picturing:

Dim x as string
x = "txtEmpName"
Me!x.controlsource = "EmpName"

Any help is appreciated. Maq [americanflag]
<insert witty signature here>
 
Dim x As Control

Set x = Me.ExclusionFile 'object name
x.ControlSource = &quot;something&quot;
Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
Hi.

Would like to help, but can you give a more descriptive version of what it is that you are actually trying to do so that I can try and recreate an example in order to answer your question.

Cheers,
Mr Big
 
No that's not quite what I need. My problem is that I don't know the name of the control until runtime. It's more like this:

controlname = dlookup(&quot;field name&quot;,&quot;tablename&quot;)
me!controlname.controlsource = &quot;blahblahblah&quot;

The actual name of the control isn't &quot;controlname&quot;, but the variable controlname holds the name of the control. Maq [americanflag]
<insert witty signature here>
 
You could try this. I'm not sure it's what you are looking for

Dim x as string
x = &quot;txtEmpName&quot;
Me(x) = &quot;EmpName&quot;

That will put the word &quot;EmpName&quot; into txtEmpName

Paul
 
Don't know if this is what you want. You can try it.

Dim x as string
x = &quot;txtEmpName&quot;
Me(x)= &quot;EmpName&quot;

Paul
 
Thanks Paul. That was the answer! Maq [americanflag]
<insert witty signature here>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top