469,266 Members | 1,768 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,266 developers. It's quick & easy.

Text visible or not visible.

Can someone help me with some code to make a text box and lable visible
only if the field in the table has something in it?

Thanks

Nov 13 '05 #1
6 18830
In the OnLoad Event of the form, put the code:

If isnull(me.textboxname) then
me.textboxname.visible = false
else
me.textboxname.visible = true
end if

<ki*********@yahoo.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Can someone help me with some code to make a text box and lable visible
only if the field in the table has something in it?

Thanks

Nov 13 '05 #2
Insert this code in the form's (or report's) code module:
(Assuming that the form is bound to a table or query and assuming that
the field myfieldname is bound to a field in the table by the same
name:
example - you have a table named Contacts and in that table you have a
field named LastName. The form is bound to the table Contacts and the
field ypu want to hide or show is named LastName and is bound to the
field LastName in the Contacts table.)

Private Sub Form_Load()
If len(me!myfieldname) > 0 then
me.myfieldname.visible = true
me.mylabelname.visible = true
Else
me.myfieldname.visible = false
me.mylabelname.visible = false
End If
End Sub

Also to avoid having the field flicker when the form loads, set the
visible property of the field and the label to false so that it loads
hidden but then is made visible only if it is full.

kingphil...@yahoo.com wrote:
Can someone help me with some code to make a text box and lable visible only if the field in the table has something in it?

Thanks


Nov 13 '05 #3
Put the following code in the form's OnCurrent event:
Me!NameOfTextbox.Visible = Not IsNull(Me!NameOfTextbox)

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com


<ki*********@yahoo.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Can someone help me with some code to make a text box and lable visible
only if the field in the table has something in it?

Thanks

Nov 13 '05 #4
It's best to avoid the user of If IsNull(me.textboxname) Then since it
does not handle blank rather than null strings...

Nov 13 '05 #5
Just to note putting code in the Load event will only give you what you want
when the form opens. When you navigate from record to record, you will not
get what you want. Coding the form's Current event will give you what yoy
want when the form opens as well as when you navigate from record to record.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
<ki*********@yahoo.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Can someone help me with some code to make a text box and lable visible
only if the field in the table has something in it?

Thanks

Nov 13 '05 #6
True, but the person asked "only if the field has something in it"
If it has a space in it, it contains something.
If not, If isnull will perform the function....
Not to quibble with you, it was just a quick answer.
I could write the other method as well, just longer.
"laurenq uantrell" <la*************@hotmail.com> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.com...
It's best to avoid the user of If IsNull(me.textboxname) Then since it
does not handle blank rather than null strings...

Nov 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by Randy Starkey | last post: by
4 posts views Thread by Arif Çimen | last post: by
6 posts views Thread by Johnny Holland | last post: by
2 posts views Thread by george.leithead | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.