Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Userform setfocus problem

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Userform setfocus problem

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.
--
Regards,
Tom Ogilvy


"Martin Hibberd" wrote in message
...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SOme problem on VBA Userform allissonlu Excel Programming 2 August 13th 04 01:34 AM
SetFocus to first textbox on userform upon Userform1.Show Paul Simon[_3_] Excel Programming 6 February 11th 04 04:31 PM
SetFocus Problem Todd Huttenstine[_2_] Excel Programming 2 January 19th 04 10:50 PM
TextBox SetFocus Problem Tom Ogilvy Excel Programming 1 September 12th 03 01:27 PM
SetFocus problem RFraley Excel Programming 2 September 7th 03 01:18 PM


All times are GMT +1. The time now is 12:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"