LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default SetFocus not working

I have a userform for user to input a item number (3 digits) and quantity.
When enter is pressed to advance to next textbox, the following macro
executes to see if the item number is a valid entry. As far as I can tell,
it works fine except for the SetFocus if entry is INVALID. You will see the
msgboxes so I can determine if FIND is working properly.

However, when it goes to the INVALID section, the focus is set on txtQty. I
even had txtitemnum = "TEST" to see if it would place TEST in textbox and it
did. If the entry is invalid, then the textbox is cleared and suppose to set
focus back to the textbox for user to try a different item number.

Private Sub txtitemnum_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Dim c1, c2 As Range
If KeyCode = 13 Then
Set c1 = Sheets("Items").Range("A3")
Set c2 = c1.End(xlDown)
If Not c1.Find(What:=(txtitemnum), LookAt:=xlWhole,
Searchorder:=xlByRows, _
SearchDirection:=xlNext) Is Nothing Then
MsgBox "Valid Entry"
txtQty.SetFocus
Else
MsgBox "Invalid Entry -- Retry"
txtitemnum.Value = ""
txtitemnum.SetFocus <---Does not happen
End If
End If
End Sub


Thanks for your help.
Les
 
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
SetFocus not working as I would expect [email protected] Excel Programming 0 May 3rd 07 02:37 AM
SetFocus? plh Excel Programming 1 May 1st 06 03:01 AM
SetFocus not working Henry T Excel Programming 1 September 15th 05 05:33 PM
SetFocus testing Tim[_44_] Excel Programming 3 September 7th 05 07:20 PM
setfocus Dean Reardon Excel Programming 2 December 15th 04 12:18 PM


All times are GMT +1. The time now is 10:08 PM.

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"