Select Text in Textbox from VBA

Select Text in Textbox from VBA

Post by Chris F vi » Fri, 13 Jun 2008 20:03:46

Hello all-
I am using Access 2007, and have a form with a text box that a user is to
enter their User Name in. A check is performed on the After_Update Event of
the text box and if the user name is not found in the BE, an error message is
displayed and the text box is to gain focus and the value entered in the text
box using the SelLength function is to be highlighted, however, it does not
appear to be working properly. Here is the code:
If intCheckName = 0 Then
'Show Error Message
Me.ErrorMessage.Caption = "User does not Exist."
Me.ErrorMessage.Visible = True

Me.LoginPassword.Value = ""
Me.LoginPassword.Enabled = False

Me.btnLogin.Enabled = False

With Me.LoginName
.SelStart = 0
.SelLength = Len(Me.LoginName.Text)
End With

What appears to be happening is that the text in this field is highlighted
breifly, but then the cursor moves to infront of the text. I also tried Me.
LoginName.SelStart = Len(Me.LoginName.Text) and yet the cursor remains
infront of the text and not at the end of the text as I thought the above
code would produce.
Is there something I am missing here?
Thank you in advance for any help that you all may be.
Chris F

Message posted via

Select Text in Textbox from VBA

Post by Linq Adams » Fri, 13 Jun 2008 21:25:51


.SelLength = Len(Me.LoginName.Text)


.SelLength = Len(Me.LoginName.Value)

There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via


Select Text in Textbox from VBA

Post by tobesurvey » Fri, 13 Jun 2008 22:15:03

Thank you for your response, however when I change the code as suggested, it
still places the cursor in front of the text, and the value is not
highlighted. Is this a problem in Access 2007?

Message posted via