-
Solved: What's the default RGB values in forms?
I'm setting up a vba form that will change the background color of a frame if the user doesn't select something in it. If they go back and select something, I want to change the background color back to normal (gray), but I don't know what the values are for that and can't seem to get it right.
Can anyone help?
Thanks!
Cheryl
-
Hi Cheryl,
Probably the best way to do this is to store the color value you want in a module level variable so you can use it when you switch back.
If you paste the code below into a new userform with a frame and a commandbutton, you'll see what I mean[VBA]'declare in 'General declarations' so it's available to all the routines
Dim ORIGINAL_COLOR As Long
Private Sub UserForm_Initialize()
CommandButton1.Caption = "New color"
'capture frame's initial back color
ORIGINAL_COLOR = Frame1.BackColor
End Sub
Private Sub CommandButton1_Click()
If CommandButton1.Caption = "New color" Then
Frame1.BackColor = RGB(255, 0, 0)
CommandButton1.Caption = "Old color"
ElseIf CommandButton1.Caption = "Old color" Then
Frame1.BackColor = ORIGINAL_COLOR
CommandButton1.Caption = "New color"
End If
End Sub
[/VBA]
K :-)

-
Awesome! It works perfectly!! Thank you so much!
Cheryl
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules