Oh Great Vicars of VBA and your Excellences of Excel,
I have a toggle button on a user form within a mutipage that I want to send to a sub. I know I am supposed to quote code - but I am not sure what it means for a control on a userform.
About the control:
Type: ToggleButton
Name: TBOC
It resides in the (container?) multipage1
Page
Name: ComputeType
Index: 5
When I execute the code I take it right to the point where it calls the sub and I take a look at what TBOC is. In the watch, TBOC is described as type "Object/ToggleButton" and the context is Wizard2016x.SimulationCapacity
Now for the actual code:
Now I've tried sticking in "ByRef" without really knowing what it does, and it doesn't seem to help. I am thinking that the problem has something to do with the context since the control is sitting in a container. I want to make the sub independent of context - that is, for any togglebutton on any page I want it to show up as vbGreen when depressed and vbButtonFace when off. (Of course, there's a TurnOffC that mirrors this one).
I actually had this working fine for one page by simply passing the control name (string) to a sub, but when I passed a control with a different context it no longer worked - so I am looking for a context independent solution.
My sometimes working sub looks like this, but I thought simply passing the control would be a far more elegant and robust solution.
Best regards,
Excel Neophyte
I have a toggle button on a user form within a mutipage that I want to send to a sub. I know I am supposed to quote code - but I am not sure what it means for a control on a userform.
About the control:
Type: ToggleButton
Name: TBOC
It resides in the (container?) multipage1
Page
Name: ComputeType
Index: 5
When I execute the code I take it right to the point where it calls the sub and I take a look at what TBOC is. In the watch, TBOC is described as type "Object/ToggleButton" and the context is Wizard2016x.SimulationCapacity
Now for the actual code:
Code:
TurnOnC (TBOC)
Sub TurnOnC(Ctrl As Control)
Ctrl.Value = True
Ctrl.BackColor = vbGreen
End Sub
Now I've tried sticking in "ByRef" without really knowing what it does, and it doesn't seem to help. I am thinking that the problem has something to do with the context since the control is sitting in a container. I want to make the sub independent of context - that is, for any togglebutton on any page I want it to show up as vbGreen when depressed and vbButtonFace when off. (Of course, there's a TurnOffC that mirrors this one).
I actually had this working fine for one page by simply passing the control name (string) to a sub, but when I passed a control with a different context it no longer worked - so I am looking for a context independent solution.
My sometimes working sub looks like this, but I thought simply passing the control would be a far more elegant and robust solution.
Code:
Sub TurnOn(name As String) Me.MultiPage1.Pages(Me.MultiPage1.Value).Controls(name).Value = True
Me.MultiPage1.Pages(Me.MultiPage1.Value).Controls(name).BackColor = vbGreen
End Sub
Best regards,
Excel Neophyte