W
WLMPilot
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
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