Setting a control who's name is stored in a variable 
Author Message
 Setting a control who's name is stored in a variable

I have a piece of code that gets the name of a text box on a form and
stores it in a variable called tmpctrl.
Later in the function, I want to set the value of the text box. (Let's
say 1000)
My problem is I do not know the correct way to set the value of the box
through vba.
When I type in:
tmpctrl = "1000"
it just sets the variable "tmpctrl" to 1000 and not the control whos
name is stored in tmpctrl.

Can anyone help??

Thanx,
Jay

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sun, 13 Apr 2003 03:00:00 GMT  
 Setting a control who's name is stored in a variable
HI
try with
        Form!Controls.item(tmpctrl) = Val
Quote:

>I have a piece of code that gets the name of a text box on a form and
>stores it in a variable called tmpctrl.
>Later in the function, I want to set the value of the text box. (Let's
>say 1000)
>My problem is I do not know the correct way to set the value of the box
>through vba.
>When I type in:
>tmpctrl = "1000"
>it just sets the variable "tmpctrl" to 1000 and not the control whos
>name is stored in tmpctrl.

>Can anyone help??

>Thanx,
>Jay

>Sent via Deja.com http://www.deja.com/
>Before you buy.



Sun, 13 Apr 2003 03:00:00 GMT  
 Setting a control who's name is stored in a variable

Try

Me!MyForm.Controls(tmpctrl) = 1000

You could alternately dimension tmpctrl as a control:

Dim tmpctrl as Control
Set tmpctrl = Me!MyForm!Control
tmpctrl = 1000

cheers,
s

Quote:

> I have a piece of code that gets the name of a text box on a form and
> stores it in a variable called tmpctrl.
> Later in the function, I want to set the value of the text box. (Let's
> say 1000)
> My problem is I do not know the correct way to set the value of the box
> through vba.
> When I type in:
> tmpctrl = "1000"
> it just sets the variable "tmpctrl" to 1000 and not the control whos
> name is stored in tmpctrl.

> Can anyone help??

> Thanx,
> Jay

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Sun, 13 Apr 2003 03:00:00 GMT  
 Setting a control who's name is stored in a variable

Sorry.  Should be

Me.Controls(tmpctrl) and
Set tmpctrl = me.control name

Me!MyForm.Controls(tmpctrl) = 1000

You could alternately dimension tmpctrl as a control:

Dim tmpctrl as Control
Set tmpctrl = Me!MyForm!Control
tmpctrl = 1000

cheers,
s

Quote:

> I have a piece of code that gets the name of a text box on a form and
> stores it in a variable called tmpctrl.
> Later in the function, I want to set the value of the text box. (Let's
> say 1000)
> My problem is I do not know the correct way to set the value of the box
> through vba.
> When I type in:
> tmpctrl = "1000"
> it just sets the variable "tmpctrl" to 1000 and not the control whos
> name is stored in tmpctrl.

> Can anyone help??

> Thanx,
> Jay

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Sun, 13 Apr 2003 03:00:00 GMT  
 Setting a control who's name is stored in a variable
Thanks Guys, Thats whaat I needed to get my head around! :)


Quote:

> I have a piece of code that gets the name of a text box on a form and
> stores it in a variable called tmpctrl.
> Later in the function, I want to set the value of the text box. (Let's
> say 1000)
> My problem is I do not know the correct way to set the value of the
box
> through vba.
> When I type in:
> tmpctrl = "1000"
> it just sets the variable "tmpctrl" to 1000 and not the control whos
> name is stored in tmpctrl.

> Can anyone help??

> Thanx,
> Jay

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Sent via Deja.com http://www.deja.com/
Before you buy.


Sun, 13 Apr 2003 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. accessing control name stored in a variable

2. Reffering to Control when Name is stored in Variable

3. control's Shape name vs control's name on worksheet in Excel 97

4. Referencing a variable name stored in a variable

5. Run-time error '91': Object variable or With block variable not set

6. Run-time error '91': - Object variable or With block variable not set

7. AC97:Set a control's property to a variable

8. Can't set node variable using treeview control

9. shorten form name in code by using variable set to the name of the form

10. Variables stored in Range Names


 
Powered by phpBB® Forum Software © phpBB Group