VBA - Help with Code (see message)

  • Thread starter Thread starter bforster1
  • Start date Start date
B

bforster1

I have written the following code to protect against a formula error i
the end user does not enter a number in the textboxes.

Private Sub TextBox40_AfterUpdate()
If TextBox40 = "" And Not IsNumeric(TextBox40) Then
MsgBox "Number Expected Here"
TextBox40.Text = ""
End If


The problem is that everytime I hit tab or enter the MsgBox fires an
the cursor jumps to the next textbox in the tab order. What I want t
happen is the MsgBox only display is a nonnumeric entry was made an
then clear the textbox but remain in it for a new entry.

Any suggestions?? Maybe someone could tell me the code to have th
cursor stay in TextBox40 if the entry is not numeric.

Thanks
 
did you try TextBox.SetFocus...? for example:

Private Sub TextBox40_AfterUpdate()
If TextBox40 = "" And Not IsNumeric(TextBox40) Then
MsgBox "Number Expected Here"
TextBox40.Text = ""
TextBox40.SetFocus
End If


- Manges
 
Back
Top