zipcode validation...

doran_doran

Registered User.
Local time
Today, 13:04
Joined
Aug 15, 2002
Messages
349
I have a form called "frmPlanContacts" where end user will populate contact information (like name, address, city, state zip and etc).

Ok, here is the delima. Zip code has to be atleast 5 digits or 9 digit.

when end user puts 5 digits system should just take the zipcode.

when end user puts 9 digits system should just take the zipcode.

when end user put 4 digits, system should prompt msgbox "zip must be atleast 5 digits and set focus to zip code and dont let end user get out of the form"

when end user put 6,7 or 8 digits, system should prompt msgbox "zip must be either 5 digits or 9 digits. and set focus to zip code and dont let end user get out of the form"

Is this duable? Any help will be appreciated.

Dianna Goldsberg

=======================================================
Here my fields (there are four different contacts), if the state is populated then end user must put a zip. If not then dont even run the validation.

txtPrimaryContactZip
txtBillingZip
txtPlanAdminZip
txtPrimaryContactPOZip
 
How does your form work, when do you want it to be validated?
________
BUY SCALE
 
Last edited:
replying

May be before Update or on Exit.

a.sinatra said:
How does your form work, when do you want it to be validated?
 
Using the beforeupdate event will enable you to "cancel" the entry of invalid data.

Code:
Private Sub TxtZipCode_BeforeUpdate(Cancel As Integer)

If IsNull(Me.TxtZipCode) Then Exit Sub
If Len(Me.TxtZipCode) = 5 Or Len(Me.TxtZipCode) = 9 Then Exit Sub
MsgBox "Zip Code must be 5 or 9 digits.  Please re-enter.", VbOKOnly, "ZipCode Validation Failure"
Cancel = True


End Sub

Note: The IsNull line permits your user to delete the invalid ZipCode and leave the field Null. You can remove this and handle nulls in another manner if you wish.

HTH

Brad.
 
Let Access do it for you.

Set your text box Input Mask to Zip code. (To give the user a HINT.)
Set the validation rule for your text box to:
(len([YourTextBox])=5) or (len([YourTextBox])=9)
 
Thank you all for help...

I will try both suggessions. Again thanks a million for all your help.

Dianna Goldsberg
 

Users who are viewing this thread

Back
Top Bottom