PDA

View Full Version : userform_activate with textbox colour change not working



epd
03-01-2012, 03:18 PM
Hi,

i am having trouble with the below.

i have a userform that opens when a button is clicked. i have it so some text box fields are a certain colour when the form opens. i have written the code for the colour to change if the text box is a different value but it isnt working.

ontop of that i then have an example of the textbox_exit sub and that doesnt work either.

what have i done wrong?

Private Sub UserForm_activate()
'Select row based on cell selection
Selection.EntireRow.Select

'TextBox and ComboBox Fillouts
'TextBox1
TextBox1.Text = ""

'TextBox2
TextBox2.Text = ""

'TextBox3
TextBox3.Text = ""

'TextBox4
TextBox4.Text = ""

'TextBox5
TextBox5.Text = ""

'TextBox6
TextBox6.Text = ""

'ComboBox1
ComboBox1.Text = "Select a name"
ComboBox1.AddItem "Select a name"
ComboBox1.AddItem "Name 1"
ComboBox1.AddItem "Name 2"
ComboBox1.AddItem "Other"

'TextBox8
TextBox8.Text = "DD.MM.YYYY"

'ComboBox2
ComboBox2.Text = "Select a name"
ComboBox2.AddItem "Select a name"
ComboBox2.AddItem "Name 1"
ComboBox2.AddItem "Name 2"
ComboBox2.AddItem "Other"

'TextBox10
TextBox10.Text = "DD.MM.YYYY"

'TextBox11
TextBox11.Text = "Name 3"

'TextBox12
TextBox12.Text = "UNKNOWN"

'TextBox13
TextBox13.Text = "Name 3"

'TextBox14
TextBox14.Text = "DD.MM.YYYY"

'TextBox and ComboBox Colours
'ComboBox1
If ComboBox1 = "Select a name" Then
Me.ComboBox1.ForeColor = RGB(150, 150, 150)
Me.ComboBox1.BackColor = RGB(255, 255, 255)
Else
Me.ComboBox1.ForeColor = 1
Me.ComboBox1.BackColor = RGB(255, 255, 255)
End If

'TextBox8
If TextBox8 = "DD.MM.YYYY" Then
Me.TextBox8.ForeColor = RGB(150, 150, 150)
Me.TextBox8.BackColor = RGB(255, 255, 255)
Else
Me.TextBox8.ForeColor = 1
Me.TextBox8.BackColor = RGB(255, 255, 255)
End If

'ComboBox2
If ComboBox2 = "Select a name" Then
Me.ComboBox2.ForeColor = RGB(150, 150, 150)
Me.ComboBox2.BackColor = RGB(255, 255, 255)
Else
Me.ComboBox2.ForeColor = 1
Me.ComboBox2.BackColor = RGB(255, 255, 255)
End If

'TextBox10
If TextBox10 = "DD.MM.YYYY" Then
Me.TextBox10.ForeColor = RGB(150, 150, 150)
Me.TextBox10.BackColor = RGB(255, 255, 255)
Else
Me.TextBox10.ForeColor = 1
Me.TextBox10.BackColor = RGB(255, 255, 255)
End If

'TextBox14
If TextBox14 = "DD.MM.YYYY" Then
Me.TextBox14.ForeColor = RGB(150, 150, 150)
Me.TextBox14.BackColor = RGB(255, 255, 255)
Else
Me.TextBox14.ForeColor = RGB(0, 0, 0)
Me.TextBox14.BackColor = RGB(255, 255, 255)
End If

End Sub
Private Sub TextBox_Exit()
'Change textbox colours after information entered
If TextBox8 = "DD.MM.YYYY" Then
Me.TextBox8.ForeColor = 1
Me.TextBox8.BackColor = RGB(255, 255, 255)
Else
Me.TextBox8.ForeColor = RGB(150, 150, 150)
Me.TextBox8.BackColor = RGB(255, 255, 255)
End If
End Sub
Private Sub CommandButton2_Click()
'Close Userform8
Unload UserForm8
End Sub

epd
03-01-2012, 04:09 PM
I would be more interested to know how to have the colour change in the combobox when the value isnt "Select a name"

the textbox colour change i dont care about anymore.