Select Text in Textbox from VBA

  • Thread starter Chris F via AccessMonster.com
  • Start date
C

Chris F via AccessMonster.com

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
.SetFocus
.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.
Regards,
Chris F
 
L

Linq Adams via AccessMonster.com

Change

.SelLength = Len(Me.LoginName.Text)

to

.SelLength = Len(Me.LoginName.Value)
 
T

tobesurveyor via AccessMonster.com

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top