Userform setfocus problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a simple form with 3 text boxes(txtBadge,txtCount,txtRet) and 1
button. I want to enter data in txtbadge, do some checking, update a counter
txtCount and return the focus to txtbadge so that the next value can be
entered. The problem is that when the AfterUpdate sub ends, the focus goes to
txtRet textbox - I want it t stay in txtBadge. The code below works OK until
the End Sub is executed. Any ideas would be welcome......

Private Sub bnExit_Click()
Unload fmReturnUsed
End Sub

Private Sub txtBadge_AfterUpdate()
txtRet.Value = "RETURNED"
txtCount.Value = Val(txtCount.Value) + 1
txtBadge.SelStart = 0
txtBadge.SelLength = Len(txtBadge.Value)
txtBadge.SetFocus
End Sub

Regards
Martin
 
Private Sub bnExit_Click()
Unload fmReturnUsed
End Sub

Private Sub txtBadge_AfterUpdate()
txtRet.Value = "RETURNED"
txtCount.Value = Val(txtCount.Value) + 1
End Sub


Private Sub txtBadge_Exit(ByVal Cancel As MSForms.ReturnBoolean)
txtBadge.SelStart = 0
txtBadge.SelLength = Len(txtBadge.Value)
If Len(txtBadge.Text) <> 0 Then
Cancel = True
End If
End Sub

You can't select the bnExit button if Cancel is set to True in the Exit
events, so I don't set it to true if the textbox is empty. You may want to
play with it to perform some other behavior.
 

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

Similar Threads


Back
Top