View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Billy B Billy B is offline
external usenet poster
 
Posts: 54
Default Userform coding problem

I have a userform in which two values are input. What I want to do is on exit
from the second text control (txtPurAmt) is clear the current data, set the
focus in the date field and be ready to input another record. What is
happening is that after I set the focus on the txt Date control, the code
wants to run again. Here is what I have so far and have commented where the
problem occurs. Any help is greatly appreciated. Thank you.

Private Sub txtPurAmt_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim strAgain As String, bYes As Boolean


Range("A9").End(xlDown).Select
ActiveCell.Offset(1, 0).Select

ActiveCell.Value = Me.txtDate.Value
ActiveCell.Offset(0, 1).Range("A1").Select

ActiveCell.Value = CCur(Me.txtPurAmt.Text)

strAgain = InputBox("Add another record?", "Add New Record?", "Yes")
If strAgain = "Yes" Then
ActiveCell.Offset(1, -1).Select
Me.txtDate.Value = ""
Me.txtPurAmt.Value = ""
bYes = True
Else
Me.txtDate.Value = ""
Me.txtPurAmt.Value = ""
bYes = False
End If

If bYes = True Then
'************
'After the next line, the code starts all over again and the
'Exit Sub line never executes.
Me.txtDate.SetFocus
Exit Sub
Else
UserForm1.Hide
Exit Sub
End If

End Sub