View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Setfocus Problem

Actually Jay was right the first time, but doesn't seem to know it.

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
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")
cancel = True
Else
TextBox1.Value = ""
cancel = True
End If
End Sub

Private Sub UserForm_Activate()
TextBox1.Value = ""
TextBox2.Value = Format(0, "Standard")
End Sub

So you don't need a kludge solution with setfocus and extra events. It is
usually best not to fight the behavior of the controls if you can help it.

--
Regards,
Tom Ogilvy




"Craig M" wrote in message
news:%qbGh.1206747$5R2.728175@pd7urf3no...
Thank You... adding the enter event for textbox2 did the trick!
Something so easy was killing me!

Thanks Again
Craig



"Jay" wrote in message
...
Sorry, my previous post should read:

"Try adding an Enter event procedure (for TextBox2)." instead of
"Try adding an Exit event procedure."
--
Jay


"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