Preventing need to hit Enter twice in UserForm

R

rob nobel

With thanks to Harald who gave me this procedure which makes sure a number
is entered into a UserForm (and works great) .......
Q. Is there a way, that when the Enter key is hit, the userform accepts the
value entered without having to hit the Enter key twice?

Private Sub TextBox1_KeyPress(ByVal _
KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub

Private Sub TextBox1_KeyDown(ByVal _
KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
If Shift = 2 Then KeyCode = 0
End Sub

Private Sub OKButton_Click()
Dim tax As String
tax = TextBox1.Text
If tax = "" Then
MsgBox "You must enter a number (without $ sign.)."
Unload Me
ufTaxWithheld.Show
Exit Sub
End If
ActiveCell = TextBox1.Value
Unload Me
End Sub
 
B

BrianB

Presumably because focus is transferred elsewhere ?
How about this :-

Private Sub TextBox1_AfterUpdate()
MsgBox ("done")
End Sub
 

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