variable controls???? HELP (1 Viewer)

tomro1

Registered User.
Local time
Today, 11:18
Joined
Jun 12, 2006
Messages
23
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

VBA idiot
Local time
Today, 02:18
Joined
Nov 4, 2004
Messages
174
"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

Registered User.
Local time
Today, 11:18
Joined
Sep 25, 2000
Messages
805
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

Nifty Access Guy
Staff member
Local time
Today, 10:18
Joined
Jul 9, 2003
Messages
16,285
I'm re writing it !!!!
 
Last edited:

tomro1

Registered User.
Local time
Today, 11:18
Joined
Jun 12, 2006
Messages
23
thanks RoyVidar, the code works perfect.
It was all in the me.controls(***)
 

Users who are viewing this thread

Top Bottom