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

HOW TO DO ?: Field level Validation

Status
Not open for further replies.

whatisahandle

Programmer
Jul 26, 2001
18
CA
Hi,

I would like to do a validation on a field an prevent the user from leaving it if the validation is unsuccessful.

To do this I do a setFocus on the current field in the Sub "txtPassword_Exit" event. But it does not work, the cursor goes to the next field anyway.

What is the standard way of doing this (keeping the focus on the current field) ?

Thanks,

Chris
 
Hi Chris!

Use the Before Update event procedure:

Private Sub YourControl_BeforeUpdate(Cancel As Integer)

If YourValidation = False Then
Call MsgBox("You must enter one of these values...")
Cancel = -1
End If

End Sub

Remember, if you are going to force the user to enter a valid entry into any control before they can leave you must give them two things. A list or format for valid entries as in the message box above and a way to leave the record without saving in case they decide not to create a record at that time.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Hi Jeff,

Thanks for your answer on this, it was quite helpful.

However I am wondering how to allow the user to cancel his operation if he decides no to go ahead: when I click the cancel button, the beforeUpdate event gets called first and I am stuck in a loop. Do you have any advice on this ?

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top