Consulting

Results 1 to 9 of 9

Thread: Active Tab change Backcolor

  1. #1
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location

    Active Tab change Backcolor

    I have a userform that I would like to have the txtbox or combobox when active to have a red backcolor so the user knows where they are. How can I do that without having to add code to all the txtboxes and cmbboxes?

  2. #2
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    If possible have it change red when entered and then white when after exiting.

  3. #3
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    It's harder than you might think unless I've missed something about assigning event sinks to the MSForms.Control object. There is a method shown by Colo here.
    Regards,
    Rory

    Microsoft MVP - Excel

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub TextBox1_Enter()
    Me.TextBox1.BackColor = RGB(255, 0, 0)
    End Sub

    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Me.TextBox1.BackColor = RGB(255, 255, 255)
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    How can I do that without having to add code to all the txtboxes and cmbboxes?
    is the tricky bit. Googling in fact located a post by you (xld) elsewhere pointing out that the Enter and Exit events are inherited from the container and therefore not exposed to the event sink (at least I think that's what you said!).
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Yeah, shame, but that is how it is.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    And there's not even a ChangeControl method of the userform to use instead.
    Regards,
    Rory

    Microsoft MVP - Excel

  8. #8
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    Yeah well I will use Xld's method I will do it for all of them manually. It works great. How can I get a list of all the color codes for excel. Like for Lite blue?

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]
    Dim i as long

    For i = 1 To 56
    cells(i,"A").value = i
    Cells(i,"B").Interior.Colorindex = i
    Next i
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •