If Empty/null field, hide label (?)

J

James

I'm trying what I thought was a very simple task, to hide a report label if
a certain text box/data field is null.

The following does nothing when the report is run.
Private Sub GroupHeader1_Format(Cancel As Integer, FormatCount As Integer)
If Me!txtServOrdered = Null Then
Me!labServOrd.Visible = False
End If
If Me!txtServRendered = Null Then
Me!labServRend.Visible = False
End If
End Sub

Sould I try to test the actual field values rather than the contents of a
text box?

My data is from a query: qryInvoices

Any suggestions appreciated
 
J

James

James said:
I'm trying what I thought was a very simple task, to hide a report label
if a certain text box/data field is null.

The following does nothing when the report is run.
Private Sub GroupHeader1_Format(Cancel As Integer, FormatCount As Integer)
If Me!txtServOrdered = Null Then
Me!labServOrd.Visible = False
End If
If Me!txtServRendered = Null Then
Me!labServRend.Visible = False
End If
End Sub

Sould I try to test the actual field values rather than the contents of a
text box?

My data is from a query: qryInvoices

Any suggestions appreciated
Resolved using:

If IsNull(Me!txtServOrdered) Then
Me!labServOrd.Visible = False
End If
If IsNull(Me!txtServRendered) Then
Me!labServRend.Visible = False
End If
 
J

John Spencer

Might I suggest you use the following to show or hide the label as appropriate.

Me.labServOrd.Visible = Not(IsNull(Me.txtServOrdered))
Me.labServRend.Visible = Not(IsNull(Me.txtServRendered))

Right now the code hides the labels, but if a later record has a value in the
relevant field the label's visible property is not set to true.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top