Here's an easy one (Referencing controls)

S

Sergio Vasquez

Hi all,
I was hoping to get some help with the following problem...

I have to create a function that will set the enable property to True for a
set of text and combo boxes on a form. They are as follows.
cboTaskLine1, txtQuantLine1, txtCommentLine1
cboTaskLine2, txtQuantLine2, txtCommentLine2
cboTaskLine3, txtQuantLine3, txtCommentLine3
....
cboTaskLine12, txtQuantLine12, txtCommentLine12


I would like to have this function set the enable property to True for the
Line Number that is passed to the function.

I initially thought of doing something like what I have below, but realized
you cannot reference the properties of the control when you refer to the
controls in this way... Me("...")

Function EnableLine(LineNo As Integer)
Me("cboTaskLine" & LineNo).Enable = True
Me("txtQuantLine" & LineNo).Enable = True
Me("txtCommentLine" & LineNo).Enable = True
End Function

Any help would be greatly appreciated!
Thanks,


Sergio
 
D

Dirk Goldgar

Sergio Vasquez said:
Hi all,
I was hoping to get some help with the following problem...

I have to create a function that will set the enable property to True
for a set of text and combo boxes on a form. They are as follows.
cboTaskLine1, txtQuantLine1, txtCommentLine1
cboTaskLine2, txtQuantLine2, txtCommentLine2
cboTaskLine3, txtQuantLine3, txtCommentLine3
...
cboTaskLine12, txtQuantLine12, txtCommentLine12


I would like to have this function set the enable property to True
for the Line Number that is passed to the function.

I initially thought of doing something like what I have below, but
realized you cannot reference the properties of the control when you
refer to the controls in this way... Me("...")

Function EnableLine(LineNo As Integer)
Me("cboTaskLine" & LineNo).Enable = True
Me("txtQuantLine" & LineNo).Enable = True
Me("txtCommentLine" & LineNo).Enable = True
End Function

What makes you think you can't do that? The only problem I can see is
that you have the name of the property wrong: it's "Enabled", not
"Enable". If you fix that, the code should work fine, though it might
be a bit clearer as

Me.Controls("cboTaskLine" & LineNo).Enabled = True
 
S

Sandra Daigle

Hi Sergio,

It actually does work - but the property is 'Enabled' not 'Enable'

Me("cboTaskLine" & LineNo).Enabled = True

When you are writing the code using this type of reference you won't get the
intellisense help when choosing the property (because VBA can't identify the
object being referenced via a string) but the property is valid and will
work.
 
M

Marshall Barton

Sergio said:
I have to create a function that will set the enable property to True for a
set of text and combo boxes on a form. They are as follows.
cboTaskLine1, txtQuantLine1, txtCommentLine1
cboTaskLine2, txtQuantLine2, txtCommentLine2
cboTaskLine3, txtQuantLine3, txtCommentLine3
...
cboTaskLine12, txtQuantLine12, txtCommentLine12


I would like to have this function set the enable property to True for the
Line Number that is passed to the function.

I initially thought of doing something like what I have below, but realized
you cannot reference the properties of the control when you refer to the
controls in this way... Me("...")

Function EnableLine(LineNo As Integer)
Me("cboTaskLine" & LineNo).Enable = True
Me("txtQuantLine" & LineNo).Enable = True
Me("txtCommentLine" & LineNo).Enable = True
End Function


Is that causing a problem? Or are you just anticipating
one?

What you have looks fine to me.
 
S

Sergio Vasquez

Thank you all for your help.... I'll be more carefull with my syntax next
time! lol

-Sergio
 

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