Using variable names for controls

S

siddahuja

Hi

I have the following variable

dim test as variant
test="test_control"

now, "test_control" is a textbox

i wanna do this:

msgbox(test.text)

This gives me an error saying object required..blah blah blah

Can any one tell me how to use the variable name in the command?

I can use the same name as the control but i am passing that name to some
function (not shown) as a variable and trying to get the values stored in the
control using the variable.
 
D

Dan Artuso

HI,
You are setting your variable to a string literal: "test_control"

What you want is:

dim test as Control
Set test = Me.test_control
 
M

Marshall Barton

siddahuja said:
I have the following variable

dim test as variant
test="test_control"

now, "test_control" is a textbox

i wanna do this:

msgbox(test.text)

This gives me an error saying object required..blah blah blah

Can any one tell me how to use the variable name in the command?

I can use the same name as the control but i am passing that name to some
function (not shown) as a variable and trying to get the values stored in the
control using the variable.


It's unlikely you really want to use the .Text property, the
..Value property is probably far more appropriate.

Anyway, you can use a string variable to refer to a
control's Value by using this syntax:
Me(text)
or if you really have to use the Text property:
Me(test).Text
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top