Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using color on an Access report

Status
Not open for further replies.

tuccokeith

Technical User
Dec 11, 2002
58
US
Can you designate a color to be associated with a field value on a report, so that the field prints on the report with a color embedded in it?


Field Priority 1 = Red
Field Priority 2 = Yellow
Field Priority 3 = Green

 
If you are just showing fields in a tabular view then I don't think so (tho I'm not the greatest Access expert so I'm quite willing and happy to be proven wrong) - if you are using text boxes to show the data then you could use the textbox change event and show the background colour dependant on the value of the textbox...

Rgds, Geoff
Si hoc legere scis, nimis eruditionis habes
Want the best answers to your questions ? - then read me baby one more time - faq222-2244
 
Hello,

What is the VBA syntax for a textbox change event to set the background color?


text box name = Status

If text box value = red

Make background color red
 
Apologies - I was thinking of FORMS not reports
You could use the report_open event tho and loop thru all the textboxes

For each ctrl in me.controls
if typename(ctrl) = "textbox" then
if ctrl.text = "red" then
ctrl.backcolor = 3
else
end if
else
end if
next


or similar

Rgds, Geoff
Si hoc legere scis, nimis eruditionis habes
Want the best answers to your questions ? - then read me baby one more time - faq222-2244
 
Hello,

I am using the following code and it the color is not printing on the report:

Private Sub Report_Open(Cancel As Integer)
For Each ctrl In Me.Controls
If TypeName(ctrl) = "textbox" Then
If ctrl.Text = "red" Then
ctrl.BackColor = 3
Else
End If
Else
End If
Next

End Sub
 
Go to design view of your report. Click on the text box Status. Click on Format on the menu bar and click on Conditional Formattin. Set up Field Value Is Equal to Red then in Condition 1, select a Red color from the Fore Color button. Click Add and do a conditon for Yellow and then one for Green. Now if status has those values, they will appear that color on the report.

Neil
 
That'd be a much better and easier solution then ;-)

Rgds, Geoff
Si hoc legere scis, nimis eruditionis habes
Want the best answers to your questions ? - then read me baby one more time - faq222-2244
 
And if you have Access 97 (no conditional formatting available), use the Format event of the section where you want to implement the color change:

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

On Error Resume Next
Select Case Me("TextBoxName")

Case "red"
Me.Detail.BackColor = 255
Case "black"
Me.Detail.BackColor = 0
Case Else
'...other cases
End Select
End Sub

As a side note: the open event is not apropriate. It fires only once. The Format event fires for each occurence of the section (for the Detail section it fires for every record returned by the report's recordsource).

HTH


[pipe]
Daniel Vlas
Systems Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top