code to auto-complete a form?

  • Thread starter Thread starter Kay
  • Start date Start date
K

Kay

I have a form to collect new customer addresses. I.ve put
[City], [State], and [ZipCode] in a table and want the
form to complete the zip without my keying it in. The
[State]'s default value is set to GA, so that's no
problem - only the zip.
(we're out in the country and the [City]'s have only 1 Zip
code per city!!!)

Is there a way to do this??
 
Kay

I think you want to try this the other way around. Even a medium sized city
in GA could have *MANY* zip codes. If it were me I wouldn't want to code
myself into a corner, by making the assumption that my app would *NEVER*
have to deal with a new customer a non-rural area.

The most common way to automate data entry is to have the user enter the Zip
code first and then do a lookup for the City and State. Look in help for
how to use Dlookup(). The code in the After Update event of the Zip code
text box might look like:

txtState.value = Dlookup("State","tblYourTable","Zip = '" & txtZip.Value
& "'")
txtCity.value = Dlookup("City","tblYourTable","Zip = '" & txtZip.Value &
"'")

The above assumes that you have the data type of your Zip code column set
as text. If you have it typed as a number, you need to fix that first or
you will never be able to have a customer that lives in the Northeast US
where the Zip Codes start with a Zero.

Ron W
 
Back
Top