PDA

View Full Version : Solved: Conditional Format of textbox on form



lifeson
04-03-2007, 05:59 AM
I am trying to get the colour of a text box on a form change colour if the value is less than todays date
Obviously this doesn't work:

Private Sub txtActiveto_Change()
If txtActiveTo.Value = "< Now()" Then
txtActiveTo.BackColor = &HFF&
Else
txtActiveTo.BackColor = &HFFFFFF
End If
End Sub

Anyone point me in the right direction please :doh:

Bob Phillips
04-03-2007, 08:11 AM
Private Sub txtActiveto_Change()
If txtActiveTo.Value = Format(Now,"hh:mm") Then
txtActiveTo.BackColor = &HFF&
Else
txtActiveTo.BackColor = &HFFFFFF
End If
End Sub

feathers212
04-03-2007, 08:50 AM
Try this. It formats the textbox after information is inputted. It requires that you have another control (textbox, combobox, etc.) on your form:


Private Sub txtActiveto_AfterUpdate()
Dim CurrDate As Date
CurrDate = Now - 1
If txtActiveto < CurrDate Then
txtActiveto.BackColor = vbRed
Else: txtActiveto.BackColor = vbWhite
End If
End Sub


As for colors, check out this site:
http://www.mvps.org/dmcritchie/excel/colors.htm

txtActiveto.BackColor = RGB(255, 0, 0)
gives you the same as

txtActiveto.BackColor = vbRed

lifeson
04-03-2007, 11:25 PM
Thanks chaps that works :clap:
Feathers, good link about colours :thumb

feathers212
04-04-2007, 05:51 AM
Thanks chaps that works :clap:
Feathers, good link about colours :thumb
Glad to help.....I've bookmarked that link for my own future projects :)