Watermark text in a form field

Kelanen

Registered User.
Local time
Today, 01:37
Joined
May 10, 2013
Messages
14
You often see (particularly on websites) a form field with greyed out text displayed in it, that disappears when typed over - so for example you could have name/address or whatever is supposed to be typed into that field showing.

I'm not looking for default text typed over or anything - a purely visual effect not stored in the tables.

Is there any easy way of doing this in Access?
 
Put another text box over the one you want this to show. Put the text in as gray in that text box's Control Source like ="Enter Value". Then in the Got Focus event you can hide it:

Code:
Private Sub ControlNameHere_GotFocus()
   Me.TextBoxNameForInputHere.SetFocus
   Me.ControlNameHere.Visible = False
End Sub

And then in the Lost Focus event of the control you would be doing the actual input with, put
Code:
Private Sub TextBoxNameForInputHere_LostFocus()
    If Len(Me.TextBoxNameForInputHere& vbNullString) = 0 Then
       Me.ControlNameHere.Visible = True
    End If
End Sub
 
That's a very slick solution!

I was looking at Input Masks, etc - I didn't think of a second text box...

Any thoughts on what event trigger you could use for the 2nd part if you expect those fields to be filled most of the time, and just want it to be visible when they are empty?
 
Any thoughts on what event trigger you could use for the 2nd part if you expect those fields to be filled most of the time, and just want it to be visible when they are empty?
Already told you - the LOST FOCUS of the actual control the real data is going in. See my code.
 
I get that for an input field. But if I have a form load with 10 fields, and most will have data for each record we step through, and only want it to show for empty fields on a given record.

I am presuming that Lost Focus only ever triggers for something subsequent to it gaining focus? Or is that where I am going wrong?
 
Okay, in the form's ON CURRENT event you can use something like this (for this example let us say we have fields named FName and the "fake" control is named FName_Fake and LName and the "fake" is named LName_Fake)
Code:
Private Sub Form_Current()
   Me.FName_Fake.Visible = (Len(Me.FName & vbNullString)=0)
   Me.LName_Fake.Visible = (Len(Me.LName & vbNullString)=0)
End Sub

And you can use that type of thing for each.
And you can do the same cod
 
Ah doing it at form level rather than field - I like that. Sounds perfect!

Just to understand the code, there's an assumed "If" in that Lenght statement?

Vbnullstring is covering the possibilitiy of a null field, rather than a used but deleted field?

Also is setting a control to 0 the same as setting it to No?
 
Ah doing it at form level rather than field - I like that. Sounds perfect!
Just for clarification, it is ADDITIONAL to the two events I already gave you.
Just to understand the code, there's an assumed "If" in that Lenght statement?
What the .Visible is looking for is a True or False and so the part after the = sign that I wrote will generate either a True or a False.
Vbnullstring is covering the possibilitiy of a null field, rather than a used but deleted field?
vbNullstring is actually the constant for "" which is an EMPTY STRING, not a NULL. Appending that vbNullstring on to a field has no real effect on something that already has an empty string in it but it will keep an error from occuring if the field is null. So, it in essence checks for both Nulls and Empty Strings.
Also is setting a control to 0 the same as setting it to No?
If it is a True/False Yes/No, 0/-1 then yes.
 
Just for clarification, it is ADDITIONAL to the two events I already gave you.

Ah, I hadn't gathered that at all - thank you.

vbNullstring is actually the constant for "" which is an EMPTY STRING, not a NULL.

Logical... lol

Thank you for the explanations - I want to learn how and why things work, rather than just copying the code.

Thanks for all your help!
 

Users who are viewing this thread

Back
Top Bottom