Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Jun 2003
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Report textbox background color (2000/SR1)

    I have a report with a textbox that needs to display a different background color based on the attached field's result. I know conditional formatting will do this, but, unfortunately, there are five different statuses that are possible. I've tried making two textboxes attached to the same field with an IIF statement manipulating the textboxes' visible property based on field results, and then setting conditional formats for those, but that didn't work.

    Is there a way to do this?

    Thanks,
    Jim Peterkin

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Report textbox background color (2000/SR1)

    You can do this in the On Format event of the section containing the text box. Here is an example for a control txtSomething in the Detail section; the color is determined by the value of another control txtStatus; of course, you will have to substitute the appropriate names, values and colors:

    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Select Case Me.txtStatus
    Case 1
    Me.txtSomething.BackColor = vbYellow
    Case 2
    Me. txtSomething.BackColor = vbRed
    Case 3
    Me. txtSomething.BackColor = vbGreen
    Case 4
    Me. txtSomething.BackColor = vbCyan
    Case 5
    Me. txtSomething.BackColor = vbMagenta
    End Select
    End Sub

  3. #3
    New Lounger
    Join Date
    Jun 2003
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Report textbox background color (2000/SR1)

    that was perfect.

    thank you very much, hans!

    jim

  4. #4
    Star Lounger
    Join Date
    Jan 2003
    Location
    Eau Claire, Wisconsin, USA
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Report textbox background color (2000/SR1)

    Hello, Hans.
    I'm trying to do the same thing (I think) as Mr. Peterkin. I modified your example to fit my situation:

    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Select Case Me.txtColor
    Case 1
    Me.txtName.BackColor = vbYellow
    Case 2
    Me.txtName.BackColor = vbBlue
    Case 3
    Me.txtName.BackColor = vbGreen
    Case 4
    Me.txtName.BackColor = vbCyan
    Case 5
    Me.txtName.BackColor = vbMagenta
    End Select
    End Sub

    txtColor has the word of a color (BLUE, GREEN, YELLOW) pulled from a table and I am trying to set the background of txtName to the color that is in txtColor. What am I missing here that is prevents this from working? (I do not get any error messages - the background just stays white.)

    Thanks.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Report textbox background color (2000/SR1)

    The "Case 1" instruction means that you are comparing the value of Me.txtColor to the literal value 1. But your text box doesn't have numeric values 1, 2, 3 etc., but string values "YELLOW", "BLUE", "GREEN" etc. So the Case statement should look like this:

    ...
    Case "YELLOW"
    Me.txtName.BackColor = vbYellow
    Case "BLUE"
    Me.txtName.BackColor = vbBlue
    ...

    (you can complete the list yourself)

  6. #6
    Star Lounger
    Join Date
    Jan 2003
    Location
    Eau Claire, Wisconsin, USA
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Report textbox background color (2000/SR1)

    Thanks, Hans. That works. (Learn something new every day!)

Posting Permissions

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