Referencing text-box name (1 Viewer)

LEXCERM

Registered User.
Local time
Tomorrow, 09:57
Joined
Apr 12, 2004
Messages
169
Hi all,

Hopefully, I can make myself understood on this one. Seems simple enough, but I just cannot work it out.

I have one line of code which reads:-
myControlName = [FORMS]![FORM1]![txt_myControlName]

Text field txt_myControlName stores the name value of another text box on that form (this value can be one of nine text boxes).

Now, from elsewhere, I have this code where I want to reference the value in that textbox:-
[FORMS]![FORM1]![myControlName] = myList.

I've tried this [FORMS]![FORM1]!['" & myControlName & "'] and other variations, but it fails each time.

Help appreciated and thanks in advance.
 

Ranman256

Well-known member
Local time
Today, 17:57
Joined
Apr 9, 2015
Messages
4,337
you dont need the brackets
myControlName = FORMS!FORM1!txt_myControlName

(only queries use the brackets) code doesnt.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 22:57
Joined
Sep 12, 2006
Messages
15,710
not sure if ranman's suggestion will work.

so you are reading the value of a textbox, which is the name of another control, and then trying to assign a value to that control?

what error do you get?
 

JohnHBooth

New member
Local time
Today, 22:57
Joined
Jun 18, 2015
Messages
4
I think this is the syntax you want:

FORMS!FORM1!Controls.Item(myControlName) = myList
 

LEXCERM

Registered User.
Local time
Tomorrow, 09:57
Joined
Apr 12, 2004
Messages
169
Thanks for your replies Ranman256 and spikepl, but neither work unfortunately.

gemma-the-husky: You've explained it 100 times better than me and that's exactly the problem: "so you are reading the value of a textbox, which is the name of another control, and then trying to assign a value to that control?"

The error I get is: DATABASE CAN'T FIND THE FIELD 'MYCONTROLNAME' REFERRED TO IN YOUR EXPRESSION.

Many thanks.
 

spikepl

Eledittingent Beliped
Local time
Today, 23:57
Joined
Nov 3, 2010
Messages
6,142
"Doesn't work" is a very useless message. It does not tell us what you did, but only that you are unhappy.

I cannot solve unhappiness.
 

LEXCERM

Registered User.
Local time
Tomorrow, 09:57
Joined
Apr 12, 2004
Messages
169
Hi JohnHBooth,

Yes that's it: FORMS!FORM1.Controls.Item(myControlName) = myList

Slight tweak with a full-stop before "Controls" rather than exclamations mark.

Thanks very much to you and everyone else that replied.

Kind regards.
 

LEXCERM

Registered User.
Local time
Tomorrow, 09:57
Joined
Apr 12, 2004
Messages
169
And spikepl, I did provide the error message which appeared and not the mis-quoted "doesn't work". I also provided the snippets of code I used which produced the error.

And if you ever do find the cure for "unhappiness", please let us know. ;)
 

Users who are viewing this thread

Top Bottom