Results 1 to 3 of 3

Thread: Solved: What's the default RGB values in forms?

  1. #1
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location

    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

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    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 :-)

  3. #3
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location
    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
  •