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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Focus/Tab return to Textbox 2

Status
Not open for further replies.

mudstuffin

Technical User
Sep 7, 2001
92
GB
I have a form in Excel, and if the user does not enter a numeric in a particular textbox, a message box pops up to advise that the entry needs to be a number.

How can I then take the focus back to that textbox so that the user can re-enter it correctly. At the moment, as soon as the message box is clciked, it switches to the next textbox as per the index.

Many Thanks.

Greg.
 
insert into the code of form something like this:

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1.Text = "" Then MsgBox "blabla"
SendKeys "+{TAB}" 'Sending SHIFT+TAB
End Sub
 

Thanks Ide for the quick response.

It has been buggin me all day and I didn't think of going down that route.

Works a treat.

Thanks again.

 
ide,
Thanx for that straight-forward solution.. :) Skip,
metzgsk@voughtaircraft.com
 
Is there any way to send a left arrow key in a similar manner to the way you sent the SHIFT+TAB?
Is there a resource for all special keys?
thanks,
llamaman
 
Do you mean that you want to move the selected cell to the LEFT?
Code:
ActiveCell.Offset(0, -1).Select
:) Skip,
metzgsk@voughtaircraft.com
 
Whoops .. using Word, but was applying this thread to my situation. :)

I do Excel VBA in my sleep, but with Word, I do not have a good handle on all of the objects.

What I'm trying to do is to come up with some obscure way to not allow a user to hit <enter> inside my text box on a word 97 form.

Thanks for the try!
llamaman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top