Conditional Formatting in a report

wllsth

Registered User.
Local time
Today, 09:36
Joined
Sep 17, 2008
Messages
81
Is it possible to do conditional formatting on a Label within a report, I know I get the option on the Control Source but what about the label attached to it. Basically if the value of the field is zero I don't want to show either the Control Source or the label ??
 
Yes - if you get to the detail section of your report (desgn mode)
right hand click on the sqaure ont he left hand side of the report (where there is a grey bar called detail then build event - code
and you should be able to work the rest out with if x = 0 then visible = false etc


exampl

If Me!multievents = True Then (working of a tick box )
Me.Label11.Visible = True
Me!Label103.Visible = True
 
I have created a text box now with some text in it and I've got the following bit of code in ON FORMAT of the Report.
Basically if field 'Outstanding' is Zero then I dont want to show the 2 text fields, TxtOut and TxtStage

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Nz(Me![Outstanding], "") = "" Then blVal = False Else blVal = True
Me!TxtOut.Visible = blVal
Me!TxtStage.Visible = blVal
End If
End Sub

Still not working
 
I have created a text box now with some text in it and I've got the following bit of code in ON FORMAT of the Report.
Basically if field 'Outstanding' is Zero then I dont want to show the 2 text fields, TxtOut and TxtStage

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Nz(Me![Outstanding], "") = "" Then blVal = False Else blVal = True
Me!TxtOut.Visible = blVal
Me!TxtStage.Visible = blVal
End If
End Sub

Still not working





I see two things worth noting.
  1. The variable blVal does not appear to be defined.
  2. The If statement may not be doing what you want it to.
I reformatted the If Statement according to the rules as I understand them, and it looks like the following:
Code:
[FONT=Courier New]Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)[/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New]    If Nz(Me![Outstanding], "") = "" Then [/FONT]
[FONT=Courier New]        blVal = False [/FONT]
[FONT=Courier New]    Else [/FONT]
[FONT=Courier New]        blVal = True[/FONT]
[FONT=Courier New][COLOR=red][B]        Me!TxtOut.Visible = blVal[/B][/COLOR][/FONT]
[FONT=Courier New][COLOR=red][B]        Me!TxtStage.Visible = blVal[/B][/COLOR][/FONT]
[FONT=Courier New]    End If[/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New]End Sub [/FONT]

I think what you really want is more likely
Code:
[FONT=Courier New]Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)[/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New]    If Nz(Me![Outstanding], "") = "" Then [/FONT]
[FONT=Courier New]        blVal = False [/FONT]
[FONT=Courier New]    Else [/FONT]
[FONT=Courier New]        blVal = True[/FONT]
[FONT=Courier New]    End If[/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New][COLOR=red][B]    Me!TxtOut.Visible = blVal[/B][/COLOR][/FONT]
[FONT=Courier New][COLOR=red][B]    Me!TxtStage.Visible = blVal[/B][/COLOR][/FONT]
[FONT=Courier New] [/FONT]
[FONT=Courier New]End Sub [/FONT]
 
I have tried the following code just to try and make these fields invisible and I still cant.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.[TxtOut].Visible = False
Me.[TxtStage].Visible = False
End Sub

Is it to do with putting the code within 'On Format' on the detail portion of my report ??
 
What version of Access? That event won't fire in 2007 when the report is opened in the new report view.
 
Its Access 2007, what options should I use ??
 
Sorted it now thanks. Apparently you can do conditional formatting one field based on results of another. Should have tried this before.

Thanks
 

Users who are viewing this thread

Back
Top Bottom