View Full Version : variable controls???? HELP


tomro1
01-17-2008, 11:55 AM
ok, is there a was to put into a string or field the name of a control that is on your form, like a label, and then summon that name from the string and set it as a control in your code, like this but then in a way that works:

dim str as string
private sub button1_click()
dim ctl as control

str = "label1"
set ctl = str.name
ctl.caption = "works"

end sub

now this is just an example, but does anyone know in what way this is possible?

johndoomed
01-17-2008, 12:11 PM
"set it as a control in your code" - Can you please describe what you want your function to do? I, at least, need a bit more info..

RoyVidar
01-17-2008, 12:30 PM
Be careful with your declarations. Str is a function, and therefore shouldn't be used as variable name.

Dim TheControlName as string
Dim ctl as Access.Control
TheControlName = "lblMyLabel"
set ctl = me.controls(TheControlName)
ctl.caption = "whatever"
set ctl = nothing

Uncle Gizmo
01-17-2008, 02:44 PM
I'm re writing it !!!!

jdraw
01-17-2008, 03:10 PM
Not exactly sure of what you are asking. But I think you are looking for the Tag property.
Here is a link that has some access tips. Scroll down to the Tag property for an example.
Hope this helps.

Link is http://www.techiwarehouse.com/cms/articles.php?cat=53

tomro1
01-17-2008, 11:00 PM
thanks RoyVidar, the code works perfect.
It was all in the me.controls(***)