Archive of Mr Excel Message Board


Back to Forms in Excel VBA archive index
Back to archive home

.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


Check out our Excel Resources

Re: .Setfocus

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.


This archive is from the original message board at www.MrExcel.com.
All contents © 1998-2004 MrExcel.com.
Visit our online store to buy searchable CD's with thousands of VBA and Excel answers.
Microsoft Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.