Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Visual Basic (https://www.askmehelpdesk.com/forumdisplay.php?f=469)
-   -   Changing detail's color in reports (https://www.askmehelpdesk.com/showthread.php?t=13379)

  • Oct 5, 2005, 11:00 AM
    erosinski
    changing detail's color in reports
    I need to change the color of a row in the details if a certain field contains a certain text. Ex: field status =shipped so make the row green, status = packed make the row red etc. conditional formatting will only change the one field. If anyone has any ideas let me know
  • Oct 5, 2005, 11:39 AM
    erosinski
    never mind, figured it out. Here's the solution in case someone needs it someday.

    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If [status] = "Needs Packed" Then 'status is the field it is checking for a value
    status.ForeColor = RGB(255, 0, 0) 'rgb(,, ) is the red, green blue values of colors
    antshipdate.ForeColor = RGB(255, 0, 0)
    sorder.ForeColor = RGB(255, 0, 0)
    smfgnum.ForeColor = RGB(255, 0, 0) 'these are all the fields you change colors of
    companyname.ForeColor = RGB(255, 0, 0)
    prodno.ForeColor = RGB(255, 0, 0)
    shipqty.ForeColor = RGB(255, 0, 0)

    End If
    end sub
  • Oct 6, 2005, 05:58 AM
    ScottGem
    A few points here.

    First, when asking how to do something with software it would help if you gave the software name and version. There was no way for anyone to answer based on your first post since you didn't mention the platform.

    Second, It appears you are using Microsoft Access from your second post. However, your code is not complete. You should provide an Else clause to format the controls if the condition is not met. Also while RGB function you used will work, there are other ways as well. If you are using a primary color you could just use:

    controlname.Forecolor=Green or Red

    If you want a more specific color, format the control, then look at the number listed in the Property dialog, then use that number.

    Finally, I've done this a different way. Rather then change each control, what I've done is put a box object behind all the controls. I've then made the BackStyle of the controls as transparent. Then all I do is change the backcolor of the box depending on the fields value. This highlights the row more clearly (especially if you aren't using a color printer).
  • Oct 6, 2005, 06:17 AM
    erosinski
    I wrote this in a hurry, I use rgb because I played with opengl too much, and I did use a box at first but my boss is very stingy with the amount of toner we use. I did use an else, but only posted code for the block I was having problems with. If I had more than 3 "status" then I would have used case and not if statements. And you are right about the platform issue, I am members of a few forums and the others are strictly access 2003
  • Oct 6, 2005, 09:37 AM
    ScottGem
    No problem I was just making some suggestions and pointing out some issues to others who might try your solution.

    One point on the toner issue. You can change the background of the controls to Normal, so the whole row won't have the colored background. But, in my opinion, using a box whill make the highlight morer apparent.

  • All times are GMT -7. The time now is 11:18 AM.