Referring to a control

  • Thread starter Thread starter Guest
  • Start date Start date
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!!!
 
Hi -

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

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

John
 
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.
 
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!!!
 
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!!!
 
Back
Top