PDA

View Full Version : [SOLVED] Change Textbox and Combobox Back Color



nimesh29
09-21-2017, 09:32 AM
Hi-
I am trying to change Textbox and Combobox back color. I tried using the code below but nothing happens!
I like to apply the background color change to all my Textboxes and Combobox on the userform.

To change textbox:


Private Sub textbox3_Change()
textbox3.BackColor = RGB(75, 116, 71) 'Dark Green
End Sub


Thanks.

mdmackillop
09-21-2017, 10:46 AM
Private Sub Test()
For Each ctrl In UserForm1.Controls
If UCase(TypeName(ctrl)) = "TEXTBOX" Or UCase(TypeName(ctrl)) = "COMBOBOX" Then
ctrl.BackColor = RGB(75, 116, 71)
End If
Next
UserForm1.Show False
End Sub

nimesh29
09-21-2017, 12:17 PM
mdmackillop,
I just gave this a try but, nothing?
I even created a new textbox to see if it would work but, no change.

Nimesh

mdmackillop
09-21-2017, 02:12 PM
Can you post your workbook?

Kenneth Hobs
09-21-2017, 07:54 PM
Both work for me.

Private Sub UserForm_Initialize()
Dim ctrl As Control
For Each ctrl In UserForm1.Controls
If UCase(TypeName(ctrl)) = "TEXTBOX" Or UCase(TypeName(ctrl)) = "COMBOBOX" Then
ctrl.BackColor = RGB(75, 116, 71)
End If
Next
End Sub


Private Sub textbox3_Change()
TextBox3.BackColor = RGB(75, 116, 71) 'Dark Green
End Sub

nimesh29
09-22-2017, 06:09 AM
Kenneth-
That worked, the only difference I see is from mdmackillop code is "Userform1.show" line.

Quick question: Would I be able to add "label' to control font style and color to this code?

Thank You.

Kenneth Hobs
09-22-2017, 07:52 AM
Private Sub UserForm_Initialize()
Dim ctrl As Control
For Each ctrl In UserForm1.Controls
With ctrl
Select Case UCase(TypeName(ctrl))
Case "TEXTBOX", "COMBOBOX"
.BackColor = RGB(75, 116, 71)
Case "LABEL"
.BackColor = vbRed
With .Font
.Name = "Times New Roman"
'.FontStyle = "Bold Italic" 'No, errors
.Bold = True
.Italic = True
.Size = 12
End With
Case Else
End Select
End With
Next ctrl
End Sub

nimesh29
09-22-2017, 10:12 AM
WOW! Thank you!

Nimesh
:beerchug: