Report Highlight IF

maw230

somewhat competent
Local time
Today, 01:58
Joined
Dec 9, 2009
Messages
522
So, I found this piece of code online and want to use it in a Report:

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

'Set the backstyle to normal (default is usually transparent)
DIVISION.BackStyle = 1

If DIVISION = "1" Then
DIVISION.BackColor = vbRed

Else
DIVISION.BackColor = vbWhite
End If

End Sub

The difference is that I would like to Highlight Division if it is selected from a Listbox (name?) on a form control. The form control provides a parameter for a query, and the query provides the data for the report. So, if the user selects "Division 1" on the form control, "Division 1" will be highlighted on the report.
 
Are we talking a multi-select listbox which has to be looped through or a single-select one where it's a simple comparison?
 
I suppose it's a single-select. The list-box data source is a simple select query.
 
Replace bolded parts with the name of the form & listbox and try something like this:

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

'Set the backstyle to normal (default is usually transparent)
DIVISION.BackStyle = 1

If DIVISION = Forms![B]FormName!ControlName[/B] Then
   DIVISION.BackColor = vbRed
Else
   DIVISION.BackColor = vbWhite
End If

End Sub
 
Replace bolded parts with the name of the form & listbox and try something like this:

I am trying that as I speak!
 
Yes! Worked just fine. Thank you brighton.
 

Users who are viewing this thread

Back
Top Bottom