Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 3rd, 2007, 05:13 AM
Registered User
 
Join Date: Feb 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Verifying Zip Code Range

Hello I'm trying to verify Zip Code for TX. I want to set the range from 73 to 79. If the ZipCode doesn't fall into that range then it will alert the user of their mistake. Any tips on how to set the range from 73 to 79? I'm very new to VBA and is just learning. Below is what I have so far.

Private Sub Postal_Code_BeforeUpdate(Cancel As Integer)
If IsNull([Postal Code]) Then
strMsg = "You must enter a Zip Code"
strTitle = "Zip Code Required"
MsgBox strMsg, vbOKOnly, strTitle
Cancel = True

Else
If Me.State = "TX" Then
strFirstTwo = Left([Postal Code], 2)
strMsg = "Wrong Zip Code"
strTitle = "Zip Code Error"
MsgBox strMsg, vbOKOnly, strTitle
End If
End If



 
Old February 5th, 2007, 08:40 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I would take the Left() in a CInt() and make the string an Integer instead. So:

Dim iFirstTwo as Integer

If Me.State = "TX" Then
   iFirstTwo = Left(CInt([PostalCode]), 2)
   If iFirstTwo < 73 Or iFirstTwo = > 79 Then
     strMsg = "Wrong Zip Code"
     strTitle = "Zip Code Error"
     MsgBox strMsg, vbOKOnly, strTitle
   End If
End If

Or you may want to do this since you are already typing the variable:

iFirstTwo = Left([PostalCode], 2)

Did that work?



mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
ZIP with code is broken! CROmagnon BOOK Beginning CSS: Cascading Style Sheets for Web Design, 2nd Ed; ISBN: 978-0-470-09697-0 2 May 23rd, 2008 11:28 AM
Need a zip code radius finder and calculator. baburman ASP.NET 2.0 Professional 4 December 10th, 2007 10:14 AM
Write .NET code in .ZIP File in place of .aspx savan_thakkar ASP.NET 1.0 and 1.1 Professional 3 November 2nd, 2006 08:28 AM
Chapter 5 -- Sample 1: Zip Code Extract mt BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 1 February 20th, 2006 04:41 PM
Ch4 Runtime Error 91 using db source code zip file Matrix_zero BOOK: Beginning Access 2003 VBA 0 March 1st, 2005 08:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.