Referring to a control

G

Guest

Hi. I am trying to change a control based on the result of a function....
Example ReturnDay returns the day of the week as an integer. How do I refer
to a Command Button named "command" & ReturnDay?? Such as Command3...
I am trying to change the caption on that specific control.
I hope the question is clear .
Thanks in advance!!!
 
J

J. Goddard

Hi -

Use me![command3].caption = str(returnday())

You might not need the STR(), but it can't hurt.

John
 
T

Terry Kreft

You can refer to controls in a number of ways, e.g.
Me![Command3]
Me.Command3
Me(0) ' assuming Command 3 is the first control in the collection
Me("Command3")

In your case you want the last option as you can do something like
Me("Command" & ReturnDay).Caption = "New Caption"


BTW the syntax Me(0) and Me("Command3") are shorthand for Me.Controls(0) or
Me.Controls("Command3") respectively.
 
J

J. Goddard

Sorry - I misunderstood your question
J.

J. Goddard said:
Hi -

Use me![command3].caption = str(returnday())

You might not need the STR(), but it can't hurt.

John

Hi. I am trying to change a control based on the result of a function....
Example ReturnDay returns the day of the week as an integer. How do I
refer to a Command Button named "command" & ReturnDay?? Such as
Command3...
I am trying to change the caption on that specific control.
I hope the question is clear .
Thanks in advance!!!
 
G

Guest

HI. Thanks for all your all Terry and John.
I didnt see Terrys post till today. I ended up looping through the controls
to find the one I needed to change like this:

For Each ctrl In Forms!frmCalendar3
'Put the 1 on the first day
If Right(ctrl.Name, 1) = ReturnDay(Me!Text42, Me!Text44) - 1 Then
ctrl.Caption = "1"
ctrl.FontBold = True
Exit For
End If
Next ctrl

I used similiar code to change the rest of the captions.It seems to be doing
the job but I like Terrys method better.
Terry Kreft said:
You can refer to controls in a number of ways, e.g.
Me![Command3]
Me.Command3
Me(0) ' assuming Command 3 is the first control in the collection
Me("Command3")

In your case you want the last option as you can do something like
Me("Command" & ReturnDay).Caption = "New Caption"


BTW the syntax Me(0) and Me("Command3") are shorthand for Me.Controls(0) or
Me.Controls("Command3") respectively.

--

Terry Kreft


MarkSiegel said:
Hi. I am trying to change a control based on the result of a function....
Example ReturnDay returns the day of the week as an integer. How do I refer
to a Command Button named "command" & ReturnDay?? Such as Command3...
I am trying to change the caption on that specific control.
I hope the question is clear .
Thanks in advance!!!
 

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