How to display background text in a text box?

A

azu_daioh

I'm not sure how to search for this but what I want to do is to
include some kind of background message inside a text box to alert
user what type of data they should enter...for example, instead of a
blank text box - i want it to say [Enter your userid here] -- then the
message goes away as soon as the user clicks or tabs to the text box.
Similar to the search box in Microsoft ClipArt downloads -- where the
text box says "Searh All Media Type" in gray text.

Is this possible? If so, what would you call this feature so I could
search for it or if someone could post a code -- I would really
appreaciate the help.

Thank you,

Sharon
 
L

Linq Adams via AccessMonster.com

There's no native Access way to do this, but it's not difficult with a little
code.

In the Property sheet for your textbox in the Default Value property place

"[Enter your userid here]"

then use this code:

Private Sub YourTextbox_GotFocus()
If Me.YourTextbox = "[Enter your userid here]" Then
Me.YourTextbox.SelStart = 0
Me.YourTextbox.SelLength = Len(Me.YourTextbox)
End If
End Sub

Private Sub YourTextbox_Click()
If Me.YourTextbox = "[Enter your userid here]" Then
Me.YourTextbox.SelStart = 0
Me.YourTextbox.SelLength = Len(Me.YourTextbox)
End If
End Sub

This will place your prompt in the textbox, and when the user moves to the
control, either by tabbing in or clicking in, the prompt will be hilited and
the user can simply overwrite it.
 
A

azu_daioh

Thanks for the help. It works.
I have another request...is there a way to remove the default value
when the control has the focus? I tried changing value to "" but it
gives me a "type mismatch" error message.

Thanks again for the help.
 
Top