Setting A Label's Visibilty Based On A Text Box Value

J

Jim Mac Millan

Hello All,

"Access 07"

I'm trying to set a Label's visibility based on a Text Box having data
present.
I'm using the following code without any success. I just can't figure out
why this is not working.


Private Sub Detail_Paint()
If PhoneAlt.Value = Null Then
Label_AltPhone.IsVisible = False (tried this with Visible instead of
IsVisible too)
Else
Label_AltPhone.IsVisible = True
End If
End Sub

TIA
Jim
 
A

Allen Browne

Instead of trying to show/hide the label, right-click it an Change To | Text
Box.

It then has a Control Source property. Set this to:
=IIf([PhoneAlt] Is Null, Null, "Phone Alt:")

No code is needed.
As a bonus, CanShink will work.
 
R

Rob Parker

Hi Jim,

The main problem is that you cannot check for null by using " ... = Null",
since by definition null has no value; you must use the IsNull function.

And a couple of other points: the property to set is the .Visible property,
and you should be doing this in the detail section's Format event, rather
than the Print event (I'm assuming that the Detail_Paint() is a typo in your
posting). Also, the .Value property of the textbox is the default property,
so you don't need to include it explicitely.

So, what you need is:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If IsNull (PhoneAlt) Then
Label_AltPhone.Visible = False
Else
Label_AltPhone.Visible = True
End If
End Sub

You can actually do this in a single line:
Label_AltPhone.Visible = Not(IsNull (PhoneAlt))

HTH,

Rob
 
J

Jim Mac Millan

Hi Allen,

I like your suggetion. Below is an actual representation of it implemented
in Access.
In the text box Label-Mobile I'm using the Webdings font so that I can
display a cell phone image. With the IIF statement in place all of the
characters in the Webdings family are showing instead just the single one I
want.

=IIf([Mobile] Is Null,Null,"Label-Mobile:")

Is there another place I should be putting character for the cell (È) phone?

Jim

Allen Browne said:
Instead of trying to show/hide the label, right-click it an Change To | Text
Box.

It then has a Control Source property. Set this to:
=IIf([PhoneAlt] Is Null, Null, "Phone Alt:")

No code is needed.
As a bonus, CanShink will work.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Jim Mac Millan said:
Hello All,

"Access 07"

I'm trying to set a Label's visibility based on a Text Box having data
present.
I'm using the following code without any success. I just can't figure out
why this is not working.


Private Sub Detail_Paint()
If PhoneAlt.Value = Null Then
Label_AltPhone.IsVisible = False (tried this with Visible instead of
IsVisible too)
Else
Label_AltPhone.IsVisible = True
End If
End Sub

TIA
Jim
 
A

Allen Browne

Whatever text you want display, place it inside the quotes, in place of
"Label-Mobile".

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Jim Mac Millan said:
Hi Allen,

I like your suggetion. Below is an actual representation of it implemented
in Access.
In the text box Label-Mobile I'm using the Webdings font so that I can
display a cell phone image. With the IIF statement in place all of the
characters in the Webdings family are showing instead just the single one
I
want.

=IIf([Mobile] Is Null,Null,"Label-Mobile:")

Is there another place I should be putting character for the cell (È)
phone?

Jim

Allen Browne said:
Instead of trying to show/hide the label, right-click it an Change To |
Text
Box.

It then has a Control Source property. Set this to:
=IIf([PhoneAlt] Is Null, Null, "Phone Alt:")

No code is needed.
As a bonus, CanShink will work.
 
J

Jim Mac Millan

If that was a snake it would have bit me ;-)

Thanks
Jim

Allen Browne said:
Whatever text you want display, place it inside the quotes, in place of
"Label-Mobile".

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Jim Mac Millan said:
Hi Allen,

I like your suggetion. Below is an actual representation of it implemented
in Access.
In the text box Label-Mobile I'm using the Webdings font so that I can
display a cell phone image. With the IIF statement in place all of the
characters in the Webdings family are showing instead just the single one
I
want.

=IIf([Mobile] Is Null,Null,"Label-Mobile:")

Is there another place I should be putting character for the cell (È)
phone?

Jim

Allen Browne said:
Instead of trying to show/hide the label, right-click it an Change To |
Text
Box.

It then has a Control Source property. Set this to:
=IIf([PhoneAlt] Is Null, Null, "Phone Alt:")

No code is needed.
As a bonus, CanShink will work.
 

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