Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.setfocus not fired with textbox_keydown ?

Status
Not open for further replies.

ooops

MIS
Dec 21, 2000
91
US
Hi all,

I tried to use .setfocus with my textbox_keydown but it doesn't work. Any idea why ?

Private Sub txtJurCode_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

If KeyCode = vbKeyReturn Or KeyCode = vbKeyTab Then

If txtJurCode.Text = "" Then
MsgBox "You must enter a JUR Code.", vbCritical + vbSystemModal
txtJurCode.SetFocus
Exit Sub
End If
end sub
 
Try this...

Private Sub txtJurCode_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

If KeyCode = vbKeyReturn Or KeyCode = vbKeyTab Then

If txtJurCode.Text = "" Then
KeyCode = 0 'Cancel key down
MsgBox "You must enter a JUR Code.", vbCritical + vbSystemModal
txtJurCode.SetFocus
Exit Sub
End If
end sub
 
Where is second "End If" ?

And this is better event:

Private Sub Text1_Validate(Cancel As Boolean)
Cancel = Trim$(Text1.Text) = vbNullString
If Cancel Then
MsgBox "You must enter a JUR Code.", vbCritical + vbSystemModal
End If
End Sub

vladk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top