View Full Version : Report Conditional Visible Property


ebatdc
02-17-2009, 12:56 PM
I am currently completing a rather convoluted report that is intended to visually illustrate the status for measurements of success. In the table (and associated form and query) that populates my report, there is a "Status" field from which users may select "Red", "Yellow", or "Green".

I have created 3 labels overlapping on the report screen ("R", "Y", and "G") with color corresponding to the status. My plan is to code the .Visible property based on the value in the "Status" field. However, I am failing tremendously to get any movement out of the .Visible property at all. For simplicity I have embedded a text box on the report that is not visible with the Status value. The code I have attempted to use is (using MS Access 2000 DB format):

Private Sub Report_Current()

If Reports![rptMeasure]![txtStatus] = "Green" Then
Reports![rptMeasure]![lblGreen].Visible = True
Else
Reports![rptMeasure]![lblGreen].Visible = False
End If

If Reports![rptMeasure]![txtStatus] = "Yellow" Then
Reports![rptMeasure]![lblYellow].Visible = True
Else
Reports![rptMeasure]![lblYellow].Visible = False
End If

If Reports![rptMeasure]![txtStatus] = "Red" Then
Reports![rptMeasure]![lblRed].Visible = True
Else
Reports![rptMeasure]![lblRed].Visible = False
End If

End Sub

Effectively all the boxes are remaining visible based on the default properties field rather than looking to the code. I am a neophyte at this and I'm sure I'm missing something terribly obvious. Also, I know the simpler solution may be to simply have the txtStatus control visible and conditionally format that, but it doesn't give the same effect that I am looking for here.

I would appreciate any input on the code and any explanation describing the "why" of that code so I might learn from this. Thank you.

HiTechCoach
02-17-2009, 02:03 PM
I think the code may be in the wrong event.

Try moving the code to the On Format event of the section where the controls are located.

boblarson
02-17-2009, 02:05 PM
With only 3 colors, you should probably use conditional formatting instead.