Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make Label invisible if value is Null 1

Status
Not open for further replies.

jer007

Technical User
Feb 16, 2004
94
CA
How do I make the label for a combo box invisible if there is nothing selected in that combo box?
 
If IsNull(ComboBox) or ComboBox = "" Then
label.visible = False
End if

HTH
Mike

[noevil]
 
Sorry, Forgot to put where to put that

Put in the Detail_Format() event

HTH
Mike

[noevil]
 
Thanks, What's odd is that when I put that into the format section, exit the properties, then go back into the properties it gets displayed like this:
"If I"sn"ull(A"mm\end\Ty"pe) or A"mm\end\Ty"pe = T"h\en" lbl_A"m\end\Ty"pe.vi"s"ible = Fal"s"e
"

It's all messed up with quotations and slashes. Do you know what causes this?
 
You can't put it in the Format properties box it has to be in the VBA code.

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

If IsNull(ComboBox) or ComboBox = "" Then
label.visible = False
End if

End Sub

HTH
Mike

[noevil]
 
Another method that doesn't involve code is to use a text box instead of a label. Set the control source of the text box to:
="Ammend Type " + [AmmendType]
Make sure the text box is wide enough to only show the text you want to show. Set its Can Grow property to No.

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
I have to ask ... why would you not show the label of the combo box if nothing is selected. Is'nt this the time when you would most want to show the label (and entice the user to make a selection)?

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Steve,
Since this is a reports forum, I assume the combo box is on a report where a user can't make any choices. I could be wrong.

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
Duane,

Good point. Personally, I dont find myself using combo's on reports, regarding them as as a mechanism for input; though they possibly do have some advantages on reports (in terms of sourcing the data).

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Steve/Duane

Normaly I wouldn't want to do this kind of function. I have an application form that covers three types of applications, Variation Orders, Conditional Uses, and Amendments. If the user selects Amendments then they have to make a sub selection (Zoning By-Law or Development Plan). If the user selects Conditional Use or Variation in the form then the section on the report (which is what I'm using to print the form) entitled "Amendment Type" becomes not applicable. That's why I don't want it to show up if it has a null value.

If you any of you have a better idea/solution to this problem I'd love to hear it because I'm new at this and if I can make it work better I'm all ears!

Thanks.
 
jer007,
Are you suggesting that none of the suggestions for hiding the label work? mgolla's and my later suggestion should both work to hide the label of the text box is null.

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
I've tried mgolla's suggestion and it doesn't seem to work. I changed the combo box to a txt box and this is my code:

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

If IsNull(txt_AmmendType) Or txt_AmmendType = "" Then
lbl_AmendType.Visible = False
End If
End Sub

I would try you're suggestion, however, I'm not understanding what you were saying.

 
Try this code:
Code:
If Len(Me.txt_AmmendType & "") = 0 Then
    Me.lbl_AmendType.Visible = False
  Else
    Me.lbl_AmendType.Visible = True
End If
You must set the label back to visible if there is a value. Also, I prefix all my control names with "Me." for clarity.

This code assumes your text box is txt_AmmendType and your adjoining label is lbl_AmendType. Note the spelling of ammend varies in your control names. Does your code compile?


Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
Duane,

thanks for noticing the spelling error. It wasn't causing compiling errors but I did go back through all my code and fixed it. Anyway, I tried the code you suggested and still am not getting any results. Here's what I've got. Please let me know if you can figure out what I'm doing wrong. Thanks.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Len(Me.txt_AmendType & "") = 0 Then
Me.lbl_AmendType.Visible = False
Else
Me.lbl_AmendType.Visible = True
End If
End Sub
 
Does your General Declarations section of your module contain
Option Explicit
If not, then add it and compile your code.
Are you controls in the Detail Section of your report?

When you say "not getting any results", what do you mean? To trouble-shoot, add a text box close to your existing one on the report and set its control source property to:
=IIf(Len([YourFieldName] & "") = 0, "No Value", "Value")
Does this display what you expect?

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
It's working perfectly now. Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top