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

Autofill City and State by entering zip code only 1

Status
Not open for further replies.

DantheDbaseMan

Programmer
Mar 16, 2000
11
0
0
US
I have a table with the following fields: cities, zipcode and State. <br>
<br>
I would like to autofill the city and state whenever the zip code is entered within a data entry form. Can anyone help on how to do this?
 
Add code to the Zipcode_AfterUpdate event.<br>
<br>
If you have a separate &quot;Zipcode&quot; table, a simple lookup can be used to populate the City and State.<br>
<br>
Otherwise, you can just lookup the value in your existing table (obviously you won't get many &quot;hits&quot; until you start populating the table itself).<br>
<br>
Assuming your table is called &quot;Address&quot; and ZipCode is TEXT (rather than a 9 digit number), the syntax is:<br>
<br>
Me!City = DLookup(&quot;City&quot;,&quot;Address&quot;,&quot;ZipCode = &quot; & &quot;'&quot; & Me!ZipCode & &quot;'&quot;)<br>
<br>
Note: There is a single quote within the sets of double quotes (hard to see!)<br>
<br>
IF ZipCode IS a number then you don't need the single quotes around Me!ZipCode ...<br>
<br>
Me!City = DLookup(&quot;City&quot;,&quot;Address&quot;,&quot;ZipCode = &quot; & Me!ZipCode)<br>
<br>
Do the same thing for the State.<br>
<br>
You may want to add some code to check to see if there is already data in the City and State fields. You there is and it doesn't match, you may want to display a message box and get the users OK before overlaying the existing values. <br>
<br>
<br>
<p>Jim Conrad<br><a href=mailto:jconrad3@visteon.com>jconrad3@visteon.com</a><br><a href= > </a><br>
 
Hello, Jim<br>
<br>
This is DantheDbaseMan. Thank you 100 times for your help! You are awesome!<br>
<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top