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!

Using If statement

Status
Not open for further replies.

fredk

Technical User
Jul 26, 2001
708
US
Hi -I have a simple database that looks up counties based on the zip code entered - Just one table that contains zip code and county.

I set up a macro that uses the set-value action - How do I also use the If Then statement? I only have New Jersey zip codes so if someone enters a zip code not on my list, I want to give the a message.

Do I create a procedure in the after update event of entry field on my form and if so what is the structure -

Thanks in advance for your assistance!!!
 
Here's the easiest solution I have for you:

Private Sub yourfield_AfterUpdate()
Dim strCounty as string

strCounty = Nz(DLookUp("County","ZipTable","Zip = " & [your zip field]),"None")

If strCounty = "None" then
msgBox "Invalid Zip Code","Data Error"
Else
'do something with your value
End If
End Sub

Hope this helps
Shane
 
I am going to try that right now - Thanks for your help Shane - I appreciate you taking the time to help me out!!!

Fred
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top