I need to highlight text in a textbox on enter or click

AccessMan

New member
Local time
Today, 21:33
Joined
Jul 18, 2009
Messages
8
name of textbox is txt_EnterDate

I want to be able to highlight the text in the textbox when i click into it with mouse, for easy editing

I could just clear it; txt_EnterDate = ""

but the user would need to see what date was previously entered

i've already used

Private Sub txt_EnterDate_GotFocus()

'If txt_EnterDate > "" Then
'txt_EnterDate.SelStart = 0
'txt_EnterDate.SelLength = Len(txt_EnterDate)
'End If

End Sub

Thanks for replies
 
What was wrong with your GotFocus handler?
 
Change this part:

'If txt_EnterDate > "" Then

to this:

If Len(Me.txt_EnterDate)> 0 Then
 
My code was correct.

Actually, not quite. You still should change it as I showed you so it will deal with nulls and empty strings. Your code as shown was only handling empty strings.
 
Ok, i'll heed your advice.

Cheers! or Slàinte in Irish

Actually, let me modify it slightly to:

Code:
If Len(Me.txt_EnterDate & "")> 0 Then

NOW it will handle nulls and empty strings.
 

Users who are viewing this thread

Back
Top Bottom