Hiding fields if no data

Henley12

Troy University Fan
Local time
Today, 08:02
Joined
Oct 10, 2007
Messages
222
I know this should be easy, but how do I hide a field if there is no data in that field? I have a field called "other" in my report that I do not want to show if there is nothing in the field. Thanks for your help.
 
Something like the following in the OnOpen event:

if me.myfld & "" = "" then
me.myfld.visible = false
end if
 
Don't forget the Else statement too :)
 
Should be the OnFormat event Ken;)
 
I get the good ole "You entered an expression that has no value" error when I do that. And there is no OnFormat event.
 
Lol, great ken. It was actually a reminder for the OP. I wasn't chastising you :)
 
is this a subform or something?

an undefined field is different to a null value.
 
You could of course also use
Dim ctrl As Control
For Each ctrl In Me.Controls
If IsNull(ctrl) Then
ctrl.Visible = False
Else
ctrl.Visible = True
End If
 
is this a subform or something?

an undefined field is different to a null value.

No, it is just a simple report. I have a field called Other along with the corresponding label. If there is nothing in the field for that record, I don't want the field or label to show up. Obviously the field won't show up since it is empty, but I don't want the label to show up either. The above method for the OnFormat event of the detail section doesn't seem to be working. Here is my code:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.AnalysisOther & "" = "" Then
Me.AnalysisOther.Visible = False
Me.lblOther1.Visible = False
Else
Me.AnalysisOther.Visible = True
Me.lblOther1.Visible = True
End If
End Sub
 
is this running and just not working apparently, or generating an rte

try it in the detail section onprint event, rather than the onformat event - that might fix it
 
Obviously the field won't show up since it is empty, but I don't want the label to show up either.
If your label was linked to your control then you wouldn't need to seperately hide the label.

The above method for the OnFormat event of the detail section doesn't seem to be working.
Does this mean your code is working?
 
No, the code is not working. Anywhere I put it, it either generates an error or the field shows up anyway. The label is not linked to the control.
 
My guess is you are reffering to the field and not the control. Change the name of the control and place that in your code.
 
That doesn't work either. I know I've done this before, but I just can't remember where and how.
 
I believe I have it. I needed a space between the quotation marks in the If statement. Thanks for all your help.
 

Users who are viewing this thread

Back
Top Bottom