Controls Question

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

Guest

I have the name of a control ("FormName.XControl") stored in a memory
variable (YVariable) I want to set the row source of xControl by referring to
the variable YVariable.

Instead of FormName.xControl.RowSource = ListName I want
YVariable.rowsource = ListName

How do I accomplish this?

Thank you
 
The first line worked ok?
FormName.xControl.RowSource = ListName

Then did you do something like:

Set yVariable = FormName.xControl
yvariable.rowsource = listname

If it didn't work, you may want to share more of your code.
 
Thank you.


Yes, the 1st line works ok.

The name of the control that I want to set the row source for is already
stored in the memory variable called YVariable ("FormName.XControl").

After that I don't know how to refer to the control via the contents of
Yvariable.
 
Ahhh. YVariable is the name of the control--not a variable that represents the
control itself.

dim yVariable as string
yVariable = "somestring"

formname.controls(yVariable).rowsource = listname

(maybe???????)

If this code is behind the userform itself, I'd use:
me.controls(yVariable).rowsource = listname

Me represents the object that owns the code--in this case, it would be that
userform.
 
I am sorry this is so confusing -- but it does show that I don't know how to
do this -- I appreciate your help.

The name of the control is FormName.XControl it is stored in a variable
called YVariable

YVariable = "FormName.XControl"

I want to be able to say the rowsource for the control whose name is stored
in YVariable is = "ListName"
 
I would remove the characters "formname" from yVariable:

yVariable = "XControl"

Then use:
formname.controls(yVariable).rowsource = listname

But now I'm worried about what listname is.

Does listname look like an address?

dim ListName as string
listname = worksheets("Somesheet").range("a1:a10").address(external:=true)

or what???????

I am sorry this is so confusing -- but it does show that I don't know how to
do this -- I appreciate your help.

The name of the control is FormName.XControl it is stored in a variable
called YVariable

YVariable = "FormName.XControl"

I want to be able to say the rowsource for the control whose name is stored
in YVariable is = "ListName"
 
again, thank you for your help -- I did as you last suggested and all is
well. ny list name is actually a named range within the excel file and it is
referred to as "ListName". This part works fine.
 

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

Back
Top