Consulting

Results 1 to 5 of 5

Thread: Solved: Conditional Format of textbox on form

  1. #1
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location

    Solved: Conditional Format of textbox on form

    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:

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

    Anyone point me in the right direction please

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

    Private Sub txtActiveto_Change()
    If txtActiveTo.Value = Format(Now,"hh:mm") Then
    txtActiveTo.BackColor = &HFF&
    Else
    txtActiveTo.BackColor = &HFFFFFF
    End If
    End Sub
    [/vba]

  3. #3
    Try this. It formats the textbox after information is inputted. It requires that you have another control (textbox, combobox, etc.) on your form:

    [vba]
    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
    [/vba]

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

    [vba]txtActiveto.BackColor = RGB(255, 0, 0)[/vba]
    gives you the same as
    [vba]
    txtActiveto.BackColor = vbRed [/vba]

  4. #4
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location
    Thanks chaps that works
    Feathers, good link about colours

  5. #5
    Quote Originally Posted by lifeson
    Thanks chaps that works
    Feathers, good link about colours
    Glad to help.....I've bookmarked that link for my own future projects

Posting Permissions

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