I need to pass the name of a control to a procedure to change the color...but this does not seem to work...any thoughts?
Dim CTRL As Control
For Each CTRL In Controls
If TypeOf CTRL Is Label Then CTRL.BackColor = TheColor
If TypeOf CTRL Is Frame Then CTRL.BackColor = TheColor
If TypeOf CTRL Is OptionButton then ReviseColor (CTRL)
If TypeOf CTRL Is Slider Then CTRL.BackColor = TheColor
If TypeOf CTRL Is CheckBox Then CTRL.BackColor = TheColor
Next CTRL
.......
ReviseColor (CTRL as Control)
CTRL.BackColor = VbRED
...more processing
....more processing
end sub
this revise color subroutine does nothing...what's wrong?
no, I need to have ReviseColor working as it willl be called from many places....also I want it generic, so I can pass the names of several other controls to it---aso I can get as much use from it as possible...it also does other processing things that I didn't list
I can't tell what the problem may be from the little piece of code you posted. I assume that the latter part is a sub but I see no call to it, nor do I know what parameter may be passed to it as the CTRL and can not tell if there may be another line in that same sub that cancels out the color change.
You should be able to pass a control to a sub and work with it there even if the sub is in a different module but you have not provided enough info to point to the error.
Next time use [ code ] [ /code ] {without the spaces} tags around your code and indent it for readability
Option Explicit
Private Sub Command1_Click()
Dim FC As Control
For Each FC In Me.Controls
If TypeOf FC Is OptionButton Then ChangeColor FC
Next
End Sub
Private Sub ChangeColor(C As Control)
C.BackColor = vbRed
End Sub
however, an error is raised if I do...
Code:
Option Explicit
Private Sub Command1_Click()
Dim FC As Control
For Each FC In Me.Controls
If TypeOf FC Is OptionButton Then ChangeColor (FC)
Next
End Sub
Private Sub ChangeColor(C As Control)
C.BackColor = vbRed
End Sub
the only difference is the parens around my variable FC. So perhaps if you remove them from your code, your code may work...
Bookmarks