View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel.programming
Patrick Molloy[_2_] Patrick Molloy[_2_] is offline
external usenet poster
 
Posts: 1,298
Default Excel 97 - VB question

you can use the textbox's Exit event...

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1.Text = "X" Then
Cancel = True
End If
End Sub

"Old Car" wrote:

I have a form with some textboxes on it (textbox1 and textbox2). When the
user tabs from textbox1 to the textbox2, I validate the contents of the
textbox1 in the textbox1_AfterUpdate event handler. If the content textbox1
is invalid, I want to keep the cursor in textbox1, rather than tabbing to
textbox2.

I have tried using textbox1.SetFocus method in the textbox1_AfterUpdate and
textbox2_Enter event handlers. Neither worked.

What is a good way to do this? Thanks.