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.
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.
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 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?
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!
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?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.
Never mind. Figured it out. For this to work, the expression field should read:
Code:[Names] = 'Tammy'