Hiding Controls that meet certain criteria

K

Ken

Hello,
I have a report that shows what classes people want to
take. Unfortunately it was built to show non responses. I
would like to know how I could hide them in the report.
For example they can take up to 5 classes. Sometimes they
pick one so that the rest of the detail area is populated
with Choose Class Title and then 0 and then a blank
for the date they did not fill in. How can I in the report
say Hide these 3 controls if they equal Choose Class Title
and 0 and a blank for the date.
Any help would be appreciated. Thanks.
Ken
 
W

Wayne Morgan

In the Format event of the Detail section use an If statement to check the value and then
set the Visible property of the desired controls.
 
W

Wayne Morgan

Fill in the appropriate names of the controls in place of the names I have here.

If Me.txtClassTitle = 0 Then
Me.txtClassTitle.Visible = False
Me.txtTextbox2.Visible = False
Me.txtTextbox3.Visible = False
Else
Me.txtClassTitle.Visible = True
Me.txtTextbox2.Visible = True
Me.txtTextbox3.Visible = True
End If

Add additional lines for additional textboxes as needed. "Me" is shortcut for the
form/report that the code is running on, the next item is the name of the textbox, and the
3rd item is the Visible property of the textbox which is being set to True or False. In
the first line (IF....) I check for the value you say you want as the cause for hiding the
textboxes (if the class's title shows zero, then hide the textboxes).
 
G

Guest

Hi Wayne,
First of all thanks!

Here is what I did


Private Sub Detail_Format(Cancel As Integer, FormatCount
As Integer)

If Me.txtD2 = 0 Then
Me.txtD11.Visible = False
Me.txtD2.Visible = False
Me.txtdate2.Visible = False
Else
Me.txtD11.Visible = True
Me.txtD2.Visible = True
Me.txtdate2.Visible = True
End If
End Sub

When I went to the Detail section and right clicked it
came up with build event as a choice. I picked it and
typed in your code between the Private SUB line and the
End Sub line.

I tried it and it didnt work.
Also if I took it out and just did your code the report
did not run.
Any suggestions?
Ken

Basically i didnt' see a Format Event choice as you
instructed so I guessed where it may go.
 
W

Wayne Morgan

You did it correctly the first time, it needs to go between the sub statements. I just
tried it and was able to hide the controls, but that may not be exactly what you are
wanting. Why not just filter out the records you don't want. You could do this in the
query feeding the report or place a filter in the report that you don't want any records
when [Field1]=0 And [Field2] Is Null.
 

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