Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting Text In a Textbox

Status
Not open for further replies.

gharabed

Programmer
Sep 7, 2001
251
US
An embarrasingly simple question but...I am validating the value entered in a textbox. How do I set the focus back to the text box and highlight the text entered into the textbox so all the user has to do is simply type in the correct value?

I tried using: Me![MyTextBox].SetFocus
but it didn't do anything. My warning msgbox displayed but the cursor navigated to the next textbox as if I never issued the SetFocus call.

Thanks,
Greg
 
Hi Greg!

It is probably the event procedure you used. Try this:

Private Sub YourTextBox_BeforeUpdate(Cancel As Integer)

If (Put your conditions here) Then
Call MsgBox("YourMessage")
Cancel = -1
End If

End Sub

hth
Jeff Bridgham
bridgham@purdue.edu
 
That pretty much did it. Now the only question is...How do I hilight the text in the textbox programatically?
 
Nevermind...I figured it out:

ctlObj.SelStart = 0
ctlObj.SelLength = Len(ctlObj)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top