.Setfocus


Posted by Cory on July 16, 2001 10:28 AM

I have a form containing a textbox where the user will enter a part number. In the textbox's Exit event I put some code that says:

Sheet1.Range("a2") = txtP1P1.Text 'sends P# to sheet
lblP1P1.Caption = Sheet1.Range("c2") & ", " & Sheet1.Range("d2") 'c2 & d2 hold a description if one's available
If lblP1P1.Caption = "" Then 'description is sent to this label; blank if no desc.
MsgBox "This part number is currently invalid. If you'd like to have this part added " _
& (chr13) & "please contact this program's developer..." 'msg if no desc. available
txtP1P1.SetFocus '??? returns to textbox????
End If

My problem is I can't get excel to set the focus back on the textbox with the bad partnumber. It just goes onto the next one. Any help?

Cory



Posted by cpod on July 16, 2001 11:38 AM

Instead of using setfocus you could just cancel the event and the focus will remain in the original textbox.