conditionally displaying label fields

  • Thread starter Thread starter ljefferys
  • Start date Start date
L

ljefferys

Guest
I want to use an event procedure to determine whether or not a label field is visible. I have done this with table fields, but can't remember the format for doing it with labels.

If a field value is "x", then label named abc should show visible.

How can I do this?

Thanks,

Lisa
 
Hello Rich!
This could be of some use to me too, but where should it be typed exactly?
 
I am guessing in a Module but where exactly I do not know, if anyone has the answer to this I would like to know. Just started fighting with it. I tried in the Report.Open but no dice.
Edit:
I've found this seems to possibly be working in the Detail.Format area of the module
If (Me.FieldName = X) Then
Me.textbox.visible =true
End If

I set the textbox visible to no and the can shrink to yes

But I am getting them all as visible when you do this no matter what if you use the detail or in the group footer

But at least maybe that will help someone else to get started. Speaking of helping if anyone knows the answer to this delimna I would appreciate the help. Because the answer suggested above does not appear to help nor do the others I have seen on the board.
 
Last edited:
In a form's current event or a report's format event:

If Me.FieldName = "somevalue" Then
Me.textbox.visible = true
else
Me.textbox.visible = false
End If

Or, you can use Rich's shortcut method in the above events. In a form, you probablly also want to execute the code in the AfterUpdate event of Me.FieldName so that if someone changes the value to "x", you can hide the other text box immediately.

Just an aside - call me old fashioned or just plain old but I strongly prefer explicit code as in the if statement rather than non-explicit code as in Rich's example.
 
Pat you are awesome thanks!! That worked.
Just as a note for anyone else doing this. I put this in a footer for a group and also made its visible False by default and then in the code set it to true.
me.FooterName.Visible =True
Hope that helps a little more.
 
Conditionally displaying fields on a Report

I have a problem similar to this one for a report I have created. I'm using the same basic report for three different employee types: analysts, project managers, and team mentors. I'm trying to hide a field called "Days" on the report when the employee type "EmpType" is not equal to "Data Analyst". My code is placed in the On Open event of the report and is:

Code:
Option Compare Database

Private Sub Report_Open(Cancel As Integer)

If Me.EmpType <> "Data Analyst" Then
Me.Days.Visible = False
Me.Label4.Visible = False
Else
Me.Days.Visible = True
Me.Label4.Visible = True
End If

End Sub

I keep getting an error message of "Run-time error '2427': You entered an expression that has no value.

I know this to not be true because the query returns a value in this field for every record in the dataset. Now, I did notice that when writing this code that the intelli-text or whatever you call the auto-fill option did not prompt for ".Visible = True/False" when I typed it which I thought was unusual. Can you not use these expressions on Reports like you can with Forms?
 
Last edited:
Hey! I figured this out from another thread. By moving my code from the On Open event to the On format events for each report section I was able to make the fields invisible. Now to see if I can re-align objects too! :rolleyes:
 

Users who are viewing this thread

Back
Top Bottom