How to create Text Box input field watermark effect in MS Access

Shallo9

Registered User.
Local time
Today, 00:43
Joined
Nov 11, 2011
Messages
95
Hello All,

Just wondering Is there a way to make my search Text box to behave like any other search box on different browsers...

For Example
How to create Text Box input field watermark effect in MS Access
with a default text displayed and when the user enters into the textbox, the watermark disappears and the field is ready to accept input.


Any sort of help is appreciated.

Many Thanks
 
To place a “prompt message” in a Textbox use this code, replacing YourTextbox with the actual name of your Textbox:
Code:
Private Sub Form_Current()
 If Nz(Me.YourTextbox, "") = "" Then
  Me.YourTextbox = "[Enter Prompt Message Here]"
 End If
End Sub

Private Sub YourTextbox_GotFocus()
If Me.YourTextbox = "[Enter Prompt Message Here]" Then
  Me.YourTextbox.SelStart = 0
  Me.YourTextbox.SelLength = Len(Me.YourTextbox)
End If
End Sub

Private Sub YourTextbox_Click()
If Me.YourTextbox = "[Enter Prompt Message Here]" Then
  Me.YourTextbox.SelStart = 0
  Me.YourTextbox.SelLength = Len(Me.YourTextbox)
End If
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.YourTextbox = "[Enter Prompt Message Here]" Then
 Me.YourTextbox = Null
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.

If the prompt message is still in the Textbox when Access starts to Save the the Record, the Field is returned to the Null state.

You could put the code from the GotFocus and OnClick events into a separate Sub and Call it from these events, but I prefer to keep code as transparent as possible as opposed to saving a few lines of code.

Linq ;0)>
 
Last edited:
This is freaking amazing
 
Always glad when someone finds help from old threads! This is why searching the forum is important, most question have been answered before!) Giving new threads descriptive titles, rather than titles like 'Need help,' makes searching easy!

Welcome to the forum!

Linq ;0)>
 
An alternative is to use the control's format property, by inserting:

@;"your prompt"
 
missinglinq,

Code is great! Exactly what I want although is there some modification to the font or color of it? I would love this to populate in Italics just for cosmetic reasons to make it stand out. I searched yesterday unsuccessfully trying to find some code examples that I could implement. Any help would be greatly appreciated!

thanks,
Samantha
 
I did manage to figure it out, sometimes I over-think it!;)
Code:
Private Sub Form_Current()
If Nz(Me.Address, "") = "" Then
Me.Address = "Street Address"
Address.FontItalic = -1
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom