Setfocus Problem
Hi Craig -
Your code looks good. Only problem is that the Exit event fires after your
AfterUpdate event procedure and it transfers focus to TextBox2, superceeding
your TextBox1.Setfocus statement.
Try adding an Exit event procedure. If that works for you, you can remove a
few unnecessary lines from your afterupdate event.
Jay
----------
Option Explicit
Private Sub TextBox1_AfterUpdate()
Dim varOne As Long
Dim varTwo As Long
Dim varTotal As Long
If TextBox1.Value < "" And TextBox1 < 0 Then
varOne = TextBox1.Value
varTwo = TextBox2.Value
varTotal = varOne + varTwo
TextBox2.Value = Format(varTotal, "Standard")
' TextBox1.Value = ""
' TextBox1.SetFocus
' Else
' TextBox1.Value = ""
' TextBox1.SetFocus
End If
End Sub
Private Sub TextBox2_Enter()
TextBox1.Value = ""
TextBox1.SetFocus
End Sub
Private Sub UserForm_Activate()
TextBox1.Value = ""
TextBox2.Value = Format(0, "Standard")
End Sub
-----
"Craig M" wrote:
Hi there....
I am trying to clear and setfocus to textbox1 after I enter a number!
I must be setting the controls wrong because I can't get textbox1 to accept
focus without hitting enter twice.
Here is the sample code below... please help!
Option Explicit
Private Sub TextBox1_AfterUpdate()
Dim varOne As Long
Dim varTwo As Long
Dim varTotal As Long
If TextBox1.Value < "" And TextBox1 < 0 Then
varOne = TextBox1.Value
varTwo = TextBox2.Value
varTotal = varOne + varTwo
TextBox2.Value = Format(varTotal, "Standard")
TextBox1.Value = ""
TextBox1.SetFocus
Else
TextBox1.Value = ""
TextBox1.SetFocus
End If
End Sub
Private Sub UserForm_Activate()
TextBox1.Value = ""
TextBox2.Value = Format(0, "Standard")
End Sub
Thanks
Craig
|