Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 09-27-2003, 04:56 PM   #1
Uncle Gizmo
Nifty Access Guy
 
Uncle Gizmo's Avatar
 
Join Date: Jul 2003
Location: Newbury Berks UK
Posts: 10,371
Thanks: 556
Thanked 948 Times in 897 Posts
Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough
Send a message via Skype™ to Uncle Gizmo
Variable as a text box name

I want to use the content of a variable as a text box name to pass a string in to the text box.

PHP Code:
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...

Uncle Gizmo is online now   Reply With Quote
Old 09-27-2003, 06:09 PM   #2
pono1
Newly Registered User
 
Join Date: Jun 2002
Posts: 1,186
Thanks: 0
Thanked 0 Times in 0 Posts
pono1 will become famous soon enough
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
pono1 is offline   Reply With Quote
Old 09-27-2003, 07:59 PM   #3
dcx693
Registered User
 
dcx693's Avatar
 
Join Date: Apr 2003
Location: Brooklyn
Posts: 3,265
Thanks: 0
Thanked 2 Times in 2 Posts
dcx693 is on a distinguished road
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"

dcx693 is offline   Reply With Quote
Old 09-28-2003, 02:28 AM   #4
Mile-O
Back once again...
 
Mile-O's Avatar
 
Join Date: Dec 2002
Location: Glasgow, UK
Posts: 11,312
Thanks: 4
Thanked 118 Times in 108 Posts
Mile-O will become famous soon enough
Another method:


Code:
Me.Controls("txtMyText") = whatever
Mile-O is offline   Reply With Quote
Old 09-28-2003, 02:52 AM   #5
pono1
Newly Registered User
 
Join Date: Jun 2002
Posts: 1,186
Thanks: 0
Thanked 0 Times in 0 Posts
pono1 will become famous soon enough
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
pono1 is offline   Reply With Quote
Old 09-28-2003, 05:44 AM   #6
dcx693
Registered User
 
dcx693's Avatar
 
Join Date: Apr 2003
Location: Brooklyn
Posts: 3,265
Thanks: 0
Thanked 2 Times in 2 Posts
dcx693 is on a distinguished road
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).
dcx693 is offline   Reply With Quote
Old 09-28-2003, 10:05 AM   #7
Uncle Gizmo
Nifty Access Guy
 
Uncle Gizmo's Avatar
 
Join Date: Jul 2003
Location: Newbury Berks UK
Posts: 10,371
Thanks: 556
Thanked 948 Times in 897 Posts
Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough
Send a message via Skype™ to Uncle Gizmo
Quote:
Originally posted by dcx693


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!


Uncle Gizmo is online now   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump




All times are GMT -8. The time now is 07:51 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World