Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2006
    Posts
    1

    Changing font color based on criteria

    Do you know if there is a way to change the color of a font when printing a report, based on certain criteria?



    For example, if the account belongs to me, print the text in red, if it belongs to Tammy, print it in green.

  2. #2
    MGSP is offline Novice
    Windows Vista Access 2007
    Join Date
    Jan 2006
    Posts
    3
    Yes,
    Open your report in Design mode. Click on the field you want the format to be conditional. Go to the top menu toolbar and select 'Format', you will see one called 'Conditional Formatting'. If you are going to base it off another field you would select 'expression'.

    We'll say the field is 'Names' you would type IIF([Names]) = "Tammy"
    Then you would go down and select the formatting you want.

    Also on the field on the report, if there were only 2 people in Names, I would format it to be red. Then yours would all be red and 'Tammy's' would be green.

    Hope this helps.

  3. #3
    Join Date
    Mar 2006
    Posts
    5

    Access97

    I tried this in Access97 and the menus are different. Are you using an updated version? If not I'm missing something. Is there any way to do this in 97?

  4. #4
    Join Date
    Mar 2006
    Posts
    5

    Not in 97

    The 'Conditional Formatting' option must be hiding in the version I'm using. I can't find it. What I did was:

    1. Report Header or Page Header or Detail or Page Footer. What I wanted to manipulate was in Detail. So, right click, choose Properties.
    2. On the Event tab Click the '...' to the right of the On Format entry box thingy.
    3. And I copied code from somewhere and modified it to fit.

    Yes I know I didn't declare my variables and my college prof would flunk me. And no clue why Cancel and FormatCount is declared. Oh, well, it works.

    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

    'Set the backstyle to normal (default is usually transparent)
    txtProductPlan.BackStyle = 1
    txtCCEng.BackStyle = 1
    txtProd.BackStyle = 1
    txtPurch.BackStyle = 1
    txtTool.BackStyle = 1
    txtPlan.BackStyle = 1
    txtCertTest.BackStyle = 1
    txtProdEng.BackStyle = 1

    If txtProductPlan = "g" Then
    txtProductPlan.BackColor = vbGreen
    ElseIf txtProductPlan = "y" Then
    txtProductPlan.BackColor = vbYellow
    ElseIf txtProductPlan = "r" Then
    txtProductPlan.BackColor = vbRed
    Else
    txtProductPlan.BackColor = vbWhite
    End If

    If txtCCEng = "g" Then
    txtCCEng.BackColor = vbGreen
    ElseIf txtCCEng = "y" Then
    txtCCEng.BackColor = vbYellow
    ElseIf txtCCEng = "r" Then
    txtCCEng.BackColor = vbRed
    Else
    txtCCEng.BackColor = vbWhite
    End If

    Etc...

    There is an End Sub at the bottom. I guess you could change txtCCEng.BackColor to txtCCEng.ForeColor I have no clue. I'm making it up as I go.

    I aslo found a program - VB Color Picker / ColFind.exe / colpick.zip from some website that translates either "#FFFF00" in HTML, 65535 in RGB to &H00FFFF for VB. Only so much you can do with vbYellow. My boss didnt like the shade of vbBlue so I changed it to &HF4C6A6. Its more powder blue. Managers like their color!

  5. #5
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93
    Quote Originally Posted by MGSP View Post
    Yes,
    Open your report in Design mode. Click on the field you want the format to be conditional. Go to the top menu toolbar and select 'Format', you will see one called 'Conditional Formatting'. If you are going to base it off another field you would select 'expression'.

    We'll say the field is 'Names' you would type IIF([Names]) = "Tammy"
    Then you would go down and select the formatting you want.

    Also on the field on the report, if there were only 2 people in Names, I would format it to be red. Then yours would all be red and 'Tammy's' would be green.

    Hope this helps.
    I tried this, but it resulted in an "wrong number of arguements" error, presumably due to the 'IIf' function not having the requisite number of arguements. Is there something else that needs to be included in the expression field?

  6. #6
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93
    Quote Originally Posted by thekruser View Post
    I tried this, but it resulted in an "wrong number of arguements" error, presumably due to the 'IIf' function not having the requisite number of arguements. Is there something else that needs to be included in the expression field?
    Never mind. Figured it out. For this to work, the expression field should read:

    Code:
    [Names] = 'Tammy'

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 0
    Last Post: 10-24-2008, 11:20 AM
  2. Counting records based on specified criteria
    By GrnISSO in forum Queries
    Replies: 2
    Last Post: 10-04-2007, 03:07 PM
  3. Changing the record source in a form
    By lmichaud in forum Forms
    Replies: 1
    Last Post: 07-09-2006, 09:20 AM
  4. Open form based on Subform criteria
    By Suzan in forum Programming
    Replies: 0
    Last Post: 04-25-2006, 02:28 PM
  5. font of word bookmarks
    By emilylu3 in forum Programming
    Replies: 1
    Last Post: 03-09-2006, 12:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Tech Forums: Microsoft Office Forums