Need help with code to hide label (1 Viewer)

3699wat

Registered User.
Local time
Today, 18:43
Joined
Oct 28, 2002
Messages
83
I usually do not post the same problem at multiple sites, but I am desperate for help.
I am looking for the code that will set all labels in the section of one report to not visible when the corresponding fields are empty.

The report is bound to a query populated by a form. Each form receives specific info for a different person and shows it on the appropriate report.

I can get the desired result with the following code, but only if used once ( the code is set in the OnFormat event procedure of the Detail section)

If Me. TextboxA = " " or IsNull (Me.TextboxA) Then
Me.LabelNameA. Visible = False
End if

If Textbox A is empty on form 1 than report 1 shows no label and box and when Textbox A has data on form 2 both will shows. Ok so far

If I enter the in the same procedure for Textbox B and enter only data on form 2, it will do the trick for report1 (no data, no label), but on report 2 it only shows the data (as expected) but the label is gone.

Question 1
Why is this happening?
Question 2
Can someone help me with a single code that would do the trick for all empty textboxes at the same time

Thank you
 

ListO

Señor Member
Local time
Today, 23:43
Joined
Feb 2, 2000
Messages
162
Try this…

I hope I understand the question, but I think this would work on your report. Instead of using formatting, just bind the report's textbox with the following as Control Source:

=iif(forms![formname].[textboxA]="" or isnull(forms![formname].[textboxA]),"","labeltext: " & [fieldname])

If TextboxA is null or "", then nothing should print in the report's textbox. If TextboxA contains anything, then the textbox should print:
Labeltext: field data

Hope it helps.

Curt
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:43
Joined
Feb 19, 2002
Messages
43,396
Once you alter a property it stays altered. You need code on BOTH sides of the If to solve your problem.

If Me. TextboxA = " " or IsNull (Me.TextboxA) Then
Me.LabelNameA. Visible = False
Else
Me.LabelNameA.Visible = True
End if


There is no code that will operate on all fields at once. You can loop through the fields collection and do it that way though.
 

3699wat

Registered User.
Local time
Today, 18:43
Joined
Oct 28, 2002
Messages
83
Thanks for the reply.
Just as yours my code works well for a single textbox.

Pat

It looks like your idea of looping through the fields is the way to go. How do you set this up.

Marcel
 

Users who are viewing this thread

Top Bottom