Jprogrammer
Dec 19 2005, 10:48 AM
I would like to hide a label if a result in a text box is = "1". I thought I could do this via the conditional formatting but looks like I can't add that to a label. Any ideas or alteratives?
Thanks for any help!
R. Hicks
Dec 19 2005, 10:50 AM
Use the On Format event of the section where the label resides ...
Me.LabelName.Visible = Me.TextboxName <> 1
RDH
niesz
Dec 19 2005, 10:50 AM
If Me.YourTextBox = "1" Then
Me.YourLabel.Visible = False
Else
Me.YourLabel.Visible = True
End If
You may have to play with what event this is associated with on a report.
freakazeud
Dec 19 2005, 10:50 AM
Hi,
use the forms on current event or whatever other event you want:
If Me.YourControl.Value = 1 Then
Me.YourLable.Visible = False
Else
Me.YourLabel.Vlisible = True
End If
HTH
Good luck
Opps...just saw that this is report related

so use either ricky's method or add an event to the details section.
R. Hicks
Dec 19 2005, 10:52 AM
Toggle a Boolean vaule with another Boolean value ...
No need for the If/Else/End If ...
RDH
R. Hicks
Dec 19 2005, 10:53 AM
Again .. no need for the If/Else/End If ...
RDH
freakazeud
Dec 19 2005, 10:56 AM
I know that method is possible, but I just never find myself using it!
Maybe I have too much time on mind hand to write out the whole if then else
R. Hicks
Dec 19 2005, 11:02 AM
LOL ... this method is overlooked my many people ...
RDH
freakazeud
Dec 19 2005, 11:03 AM
"overlooked" or ignored?
R. Hicks
Dec 19 2005, 11:07 AM
Could be either .. I suspect ..
RDH
niesz
Dec 19 2005, 11:08 AM
I posted it that way because there are some 'unknowns' in the OPs question. It was never stated whether the textbox is a string or a value, or what the other possibilities of the textbox could be.
But you're right. It can be done more efficiently if certain things are true. Personally, I would use a hidden checkbox to negate the need for the "<>".
freakazeud
Dec 19 2005, 11:09 AM
Well...I'm glad we discussed this

Happy Holidays!
R. Hicks
Dec 19 2005, 11:11 AM
QUOTE
I would use a hidden checkbox to negate the need for the "<>"
I can't agree to that solution ..
Even if the value is a string .. it can easily be converted to a numeric value or alter the expression to handle the string value ...
Me.LabelName.Visible = Me.TextboxName <> "1"
RDH
Edited by: R. Hicks on Mon Dec 19 11:17:57 EST 2005.
R. Hicks
Dec 19 2005, 11:19 AM
LOL ...
RDH
niesz
Dec 19 2005, 11:24 AM
I still think there are too many unknows to make a definitive statement as to which method is more efficient. Is the textbox on a bound or unbound form? Can the textbox value itself be rewritten to allow for more reliable code? Is the checkbox's only purpose to toggle the label?
I hate nitpicking on threads like this. My only point was we didn't have enough info to agree. Given the full circumstance, we would probably come to the same conclusion.
R. Hicks
Dec 19 2005, 11:32 AM
Nothing "nitpicking" about this ... and I find your reply somewhat hostile ...
You should not post a reply if you don't want anyone to post a more efficient and shorter solution.
There is no need to use an If/Else/End If that requires a boolean output when evaluating 2 boolean values ...
RDH
niesz
Dec 19 2005, 11:49 AM
Ricky, I didn't mean to come across as hostile, and do apologize for that. Evaluating boolean to boolean is definately more efficient. We can both agree to that. If I sounded like this was the intent of my reply, I did not mean it to be.
What it was meant to say was there may be other ways to further improve the efficiency if more details were provided.
Hope I didn't overstep anything, here. It certainly wasn't my intent. I also hope the original poster was not offended by our conversation. Nor was it my intent to infer that they did anything wrong.
Again, I apologize.
R. Hicks
Dec 19 2005, 12:01 PM
Had me worried there for a second ...
Of couse the If/Else/End If solution will return the same result .. my point was only that it is not needed in this case.
We are here to provide correct solutions to problems being posted .. and in this case .. both solutions are correct and acceptable.
I just think that the shorter, less coding solution would be better.
RDH
niesz
Dec 19 2005, 12:02 PM
I agree.
freakazeud
Dec 19 2005, 01:15 PM
QUOTE
Is the textbox on a bound or unbound form?
I thought this was concerning a report issue?
niesz
Dec 19 2005, 01:16 PM
It was never stated where the textbox was.
freakazeud
Dec 19 2005, 01:17 PM
Well..but the thread is in the reports forum so I would assume it is on a report!
niesz
Dec 19 2005, 01:18 PM
It may be...
Jprogrammer
Dec 19 2005, 02:35 PM
Thanks everyone for the great info & interested discussion! To answer one question, the text box is located on a report not a form.
I went with this option:
CODE
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.txtType.Value = "OSHA" Then
Me.lblDOC_CPR.Visible = False
Else
Me.lblDOC_CPR.Visible = True
End If
End Sub
This works great! Now I'm trying to hide two labels if the same text box in question is = "2". I'm trying to figure out how to add two labels to the same "If" line? So basically to add to what I already have, would I do something like this??:
CODE
If Me.txtType.Value = 1 Then
Me.lblCPR.Visible = False
If
txtType.Value = 2 Then
Me.lbl10 and lbl30.Visible = False
End If
End Sub
R. Hicks
Dec 19 2005, 02:49 PM
Try using a Case Select statement ..
You can then use as many variables as ytou want by add a "Case" ...
CODE
Select Case Me.txtType
Case 1
Me.lblCPR.Visible = False
Case 2
Me.lbl10.Visible False
Me.lbl30.Visible = False
End Select
Note .. The above example is assuming that "Me.txtType" is returning a numeric value
RDH
Jprogrammer
Dec 19 2005, 03:08 PM
Thanks! What if I have a text value? I have 2 reports that I want to use this with, one returns a numeric & the other returns text.
Thanks again!!!
R. Hicks
Dec 19 2005, 03:15 PM
If the value being evaluated is a string (text) .. them enclose the values to evaluate within quotes.
Here is the same example as a text variable:
CODE
Select Case Me.txtType
Case "ABC"
Me.lblCPR.Visible = False
Case "XYZ"
Me.lbl10.Visible False
Me.lbl30.Visible = False
End Select
This should show you the difference ...
RDH
Jprogrammer
Dec 19 2005, 03:29 PM
Thanks so much!!! This works great.
R. Hicks
Dec 19 2005, 03:30 PM
No problem .. you are welcome ..

RDH
Jprogrammer
Dec 19 2005, 03:39 PM
After playing with this more I am wondering if it is possible to do this- When txtType is = 1 hide lblCPR but SHOW ALL OTHER LABELS (lbl10 and lbl30) and when txtType is = 2 hide lblCPR but SHOW lbl10 and lbl30. Is this possible?
R. Hicks
Dec 19 2005, 03:48 PM
Try ....
CODE
Select Case Me.txtType
Case 1
Me.lblCPR.Visible = False
Me.lbl10.Visible =True
Me.lbl30.Visible = True
Case 2
Me.lblCPR.Visible = True
Me.lbl10.Visible = False
Me.lbl30.Visible = False
End Select
RDH
Jprogrammer
Dec 19 2005, 04:00 PM
Once again my friend...

Works great! Thanks so much & Happy Holidays!!!
R. Hicks
Dec 19 2005, 04:04 PM
And ... Happy Holidays to you ..

RDH
Jprogrammer
Jan 3 2006, 12:06 PM
I am loving this feature where I can hide a label if the text box doesn't meet a certain criteria!
Right now I have a report that the text box is sometimes empty or Null. I wrote this:
CODE
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.PMPager.Value = ""
Then Me.Label13.Visible = False
Else: Me.Label13.Visible = True
End If
End Sub
But I'm getting an error with the "". I thought this meant the same as
Is Null ???
freakazeud
Jan 3 2006, 12:13 PM
No it means a zero length string. There is a difference between that and isnull!
Have a look at this
earlier discussion!
There are many ways to ensure a control is actual NULL.
HTH
Good luck
Jprogrammer
Jan 3 2006, 02:06 PM
Thanks! I'm not getting an error now but it's not working...

????
CODE
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Nz(Me.PMPager.Value, "") = "" Then Me.Label13.Visible = False
Me.Label13.Visible = True
End Sub
freakazeud
Jan 3 2006, 02:11 PM
Aren't you missing the else part?
HTH
Good luck
Jprogrammer
Jan 3 2006, 02:19 PM
Yeah you are right! SHEESH!!!
But now I'm getting a compile error saying:
QUOTE
Else without If
CODE
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Nz(Me.txtPMPager.Value, "") = "" Then Me.lblPager.Visible = False
Else
Me.lblPager.Visible = True
End If
End Sub
ARG!!!

(by the way, I renamed my labels and text boxes.)
Thanks for your help man!!!!!!
freakazeud
Jan 3 2006, 02:24 PM
Try to move Me.lblPager.Visible = False on a new line:
If Nz(Me.txtPMPager.Value, "") = "" Then
Me.lblPager.Visible = False
Else
Me.lblPager.Visible = True
End If
Also make sure you have no other if statements anymore anywhere.
HTH
Good luck
Jprogrammer
Jan 3 2006, 02:25 PM
I also want to add another label and text box to this. Would I write it like this?
CODE
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Nz(Me.txtPMPager.Value [color="red"] and txtSuperPager [/color] , "") = "" Then Me.lblPager [color="red"] and lblPagerSupers[/color].Visible = False
Else
Me.lblPager [color="red"]and lblPagerSupers[/color].Visible = True
End If
End Sub
freakazeud
Jan 3 2006, 02:30 PM
No you need to evaluate this seperatly:
If Nz(Me.txtPMPager, "") = "" OR Nz(Me.txtSuperPager, "") Then
Me.lblPager.Visible = False
Me.lblPagerSupers.Visible = False
Else
Me.lblPager.Visible = True
Me.lblPagerSupers.Visible = True
End If
HTH
Good luck
Jprogrammer
Jan 3 2006, 02:33 PM
I'm not receiving an error now but it's not working.
I'm sorry to bother you so much with this!!!
There is no more if statements at all in this report. Here is EVERYTHING that is in my report:
CODE
Option Compare Database
Option Explicit
_________________________________________________________
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Nz(Me.txtPMPager.Value, "") = "" Then
Me.lblPager.Visible = False
Else
Me.lblPager.Visible = True
End If
End Sub
freakazeud
Jan 3 2006, 02:38 PM
Is txtPMPager really Null or empty?
It should work as the code seems to be correct if your controls are the names you assigned there.
HTH
Good luck
Jprogrammer
Jan 3 2006, 02:44 PM
Now I'm getting an error when I try to view the report saying: Run-time error '13': Type MisMatch
Basically not all of our PM's have pager's so sometimes the textbox will have the pager number in it and other times it will not. Does that make sense??
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.