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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Holding focus on field until valid entry OnExit Event 1

Status
Not open for further replies.

SARProgrammer

Technical User
Oct 8, 2007
4
US
I am trying to force a user to enter a value > 0 in a combo box. MsgBox works fine, but focus goes to the textbox with the next tab index

I don't want the user to tab through without entering a valid value. I have been trying the following as an OnExit event (without success)

Private Sub CPR_Cert_LengthCombo_Exit(Cancel As Integer)
If CPR_Cert_LengthCombo = 0 Then
MsgBox "You must enter a value greater than zero", vbOKOnly + vbCritical, "Valid Card Length"
Me.CPR_Cert_LengthCombo.SetFocus
Else
CPR_Cert_Update
End If
End Sub

Thanks in advance
 
How about using the cancel flag?
Code:
Private Sub CPR_Cert_LengthCombo_Exit(Cancel As Integer)
If CPR_Cert_LengthCombo = 0 Then
MsgBox "You must enter a value greater than zero", vbOKOnly + vbCritical, "Valid Card Length"
Cancel = True
Else
CPR_Cert_Update
End If
End Sub
Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Glad I could help [smile]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top