Using variable names for controls

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 
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
 
Back
Top