Variable as a text box name (1 Viewer)

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 17:16
Joined
Jul 9, 2003
Messages
16,274
I want to use the content of a variable as a text box name to pass a string in to the text box.

PHP:
Dim str1 as string
let str1 = "txtBox1"

let str1 = "Text to go in Text box"

Obviously the above will let str1 = "Text to go in Text box" What I want is to let txtBox1 = "Text to go in Text box"

Any idea whats missing?

P.S. I know it can be done cause I see it in the help, oh must be 6 months ago, but i can't find it in help now :(

Any help or advice appreciated...
 

pono1

Registered User.
Local time
Today, 09:16
Joined
Jun 23, 2002
Messages
1,186
Tony,

Code:
Dim str1 as string

'Copy the thing on the right 
' to the thing on the left.
	str1 = "txtBox1"

'Copy the thing on the right 
' to the thing on the left
' and overwrite the value from
' the previous copy.
	str1 = "Text to go in Text box"

'Copy from a variable to a textbox on a form.
	Forms!txtBox1.Value = str1

Regards,
Tim
 

dcx693

Registered User.
Local time
Today, 12:16
Joined
Apr 30, 2003
Messages
3,265
To place:
"Text to go in Text box"
in the text box called
"txtBox1":

on the form where the code is running:
Me("txtBox1")="Text to go in Text box"

on a different form:
Forms("formname")("txtBox1")="Text to go in Text box"

to use the variable str1 which contains the name of the text box:
Me(str1)="Text to go in Text box"
 

Mile-O

Back once again...
Local time
Today, 17:16
Joined
Dec 10, 2002
Messages
11,316
Another method:


Code:
Me.Controls("txtMyText") = [i]whatever[/i]
 

pono1

Registered User.
Local time
Today, 09:16
Joined
Jun 23, 2002
Messages
1,186
Make that last line I posted this:

Code:
'Copy from a variable to a textbox on a form.
     Forms!FormName.txtBox1.Value = str1

I was of course testing the forum with my original line.

Also, re-reading Tony's first sentence, I'm wondering what exactly he's asking. Maybe this...

Code:
Forms!FormName.TxtBox1.Value = Forms!FormName.TxtBox1.Name

Or more like Mile's example?

Code:
Dim MyString As String
MyString = "TxtBox1"

Me.Controls(MyString) = "whatever"

Regards,
Tim
 

dcx693

Registered User.
Local time
Today, 12:16
Joined
Apr 30, 2003
Messages
3,265
Just to make things less clear...

Me.Controls("txtMyText") = whatever
as Mile posted is the more "explicit" version of:
Me("txtMyText") = whatever

The controls collection is the default collection for the "Me" object, so it's implicitly understood (by Access, that is). :D
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 17:16
Joined
Jul 9, 2003
Messages
16,274
dcx693 said:


to use the variable str1 which contains the name of the text box:
Me(str1)="Text to go in Text box"

Thank you all for your posts. The above is what i was looking for.

you know, on originally posting I thought my question was on the button, but seeing your replies I realised how "Unclear" my question Was... I'll try to be better next time!
 

Users who are viewing this thread

Top Bottom