Hide objects in report based on text in text box.

bemo

New member
Local time
Today, 15:03
Joined
Dec 12, 2007
Messages
2
I need to hide a label and text box in a report based on the text in a text box. For instance: If an employee is a Union Member, I need to hide some objects, and for the Non Union Member, leave them in place.

I figured out how to hide the objects in the report using VBA, but I don't know how to hide them based on what's in the text box.

Hope someone can help,

bemo
 
If it's a one or the other choice, I'd be tempted to use a comboBox, experience with users suggests that if you want "Union member" or "Non Union Member" as your standard text it will take about .002 nanoseconds for someone to type "Union" or "onion member" and then your checks will fail. But I digress.

Code:
If me.txtbox.value = "union member" then
  me.othertxtbox.visible = false
  'and or, you can just "lock" the box so it appears greyed out and can't be amended
  me.othertxtbox.enabled = false
else if me.txtbox.value = "non union member" then
  me.othertxtbox.visible = true
else
 msgbox "Invalid information added, please check your spelling and try again"
endif
 
Thank you so much for your reply. Based on your response, I added a combo box to my form labeled Union with a "Yes" or "No" selection. I named it cboUnion. I have a text box on my report named txtUnion with the visible property set to no. I want to reference that text box: if it's a "Yes" for Union, I want to hide a label called lblCaf and a text box called txtCaf. I created this database for my Mom a few years ago. It has made her job so much easier and I'd really like to get this to work for her. I have very limited VBA experience, as you can see. Here's what I came up with:

Private Sub Report_Open(Cancel As Integer)
If Me.txtUnion.Value = "Yes" Then
Me.txtCaf.Visible = False
Me.lblCaf.Visible = False
End If
End Sub

When I run it I get a Run-time error '2427';
You entered and expression that has no value

Sure would appreciate any more help you could give.

Thanks again, bemo
 
try =If Me.txtUnion.Value = True Then..
or If Me.txtUnion.Value = 0 then
or If Me.txtUnion.Value = -1 then

what have you tied your comob to a qry/table or field list if field list then it might be 1 or 2 depending on how you have phrased it
 
I'm trying to do the same thing but keep getting the runtime error as-well
 
A report is made up of sections which format and print at different times in the lifetime of the report. To make changes to a particular control, handle the Format event of the section in which that control resides. In the Report_Open() event, for instance, controls residing in the report footer may not even exist yet.
 
There is no need for a combo box in your form

Put the following code in the Detail Format event (presuming the controls are in the Detail section).

Code:
 if me![Union Member]= true then
    me.txtDataField.visible = false
    me.lblDataLabel.visible  = false
 else
    me.txtDataField.visible = true
    me.lblDataLabel.visible  = true
 endif
 

Users who are viewing this thread

Back
Top Bottom