473,378 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Help with Forms: How to have form lookup City and State after Zip is supplied

I think this is probably simple, but I'm having a problem figuring it
out.

I have a form that is used to enter data. I want users to be able to
enter a zip code in the form, and have the city and state come up
automatically.

I have two tables:

Table 1 (14 fields): Customer Name, Address, City, State, Zip,
Preferences, etc
Table 2 (3 fields) : City, State, Zip

The form right now is completely based on Table 1. The data entered
in the form goes into Table 1. How can I get the form to look up City
and State after the Zip is entered, and enter the new data into Table
1?

Thanks for your help.

AM
Nov 12 '05 #1
5 2856
In the AfterUpdate event of the ZipCode textbox you could use DLookup to
find the City and State then set the value of the City and State textboxes
to these results. The problem you may run into is that the Zip Code
frequently will return the city of the Post Office, not the city the person
lives in. The mail will get there with this, but the user may want to still
be able to edit the city.

Example:
Me.txtCity = DLookup("City", "Table2", "ZipCode = '" & Me.txtZipCode & "'")

You may need to adjust this slightly if the user is entering 9 digit zip
codes and your lookup table has 5 digit zip codes.

--
Wayne Morgan
MS Access MVP
"CaliSchmuck" <ma*******@bls.gov> wrote in message
news:32**************************@posting.google.c om...
I think this is probably simple, but I'm having a problem figuring it
out.

I have a form that is used to enter data. I want users to be able to
enter a zip code in the form, and have the city and state come up
automatically.

I have two tables:

Table 1 (14 fields): Customer Name, Address, City, State, Zip,
Preferences, etc
Table 2 (3 fields) : City, State, Zip

The form right now is completely based on Table 1. The data entered
in the form goes into Table 1. How can I get the form to look up City
and State after the Zip is entered, and enter the new data into Table
1?

Thanks for your help.

AM

Nov 12 '05 #2
"Wayne Morgan" <co***************************@hotmail.com> wrote:
The problem you may run into is that the Zip Code
frequently will return the city of the Post Office, not the city the person
lives in.


Which may also in a few isolated situations be in a different state.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Nov 12 '05 #3
I hope I understand the reply to the question.

May I comment that, in order for this to work, ALL possible ZIP Codes, with
their associated city and state information, have to be loaded into "Table
2". If you deal with customers/clients/donors/whatever on a nationwide
basis, that is a lot of work, and you may enter a lot of data that you'll
never need.

Perhaps it would be better, or less work, to query the existing Table 1 for
matching ZIP codes, then fill the city and state text boxes based on the
results of the query. If you add a new contact whose ZIP doesn't have any
matching data in the table, you can provide the user with an error message
that the city/state data isn't in the table, then provide a prompt to add
the new city and state info into the form they are already using. Once
that's done, that city/state info will be available the next time the same
ZIP is used. This may have an additional advantage in that you can ask the
user to verify the ZIP if you come up with no city/state data - this way you
may catch a few typos.

I maintain and upgrade a small database for an organization with 481 records
in the member table. Even though we serve a local audience, there are still
170 unique ZIP codes in the member table. I just queried it to find out. So,
it seems to me that using the information you already have might be easier,
rather than constructing, then maintaining, another table.

Just my $0.02, as they say.
Steve E.

"Wayne Morgan" <co***************************@hotmail.com> wrote in message
news:ew*****************@newssvr24.news.prodigy.co m...
In the AfterUpdate event of the ZipCode textbox you could use DLookup to
find the City and State then set the value of the City and State textboxes
to these results. The problem you may run into is that the Zip Code
frequently will return the city of the Post Office, not the city the person lives in. The mail will get there with this, but the user may want to still be able to edit the city.

Example:
Me.txtCity = DLookup("City", "Table2", "ZipCode = '" & Me.txtZipCode & "'")
You may need to adjust this slightly if the user is entering 9 digit zip
codes and your lookup table has 5 digit zip codes.

--
Wayne Morgan
MS Access MVP
"CaliSchmuck" <ma*******@bls.gov> wrote in message
news:32**************************@posting.google.c om...
I think this is probably simple, but I'm having a problem figuring it
out.

I have a form that is used to enter data. I want users to be able to
enter a zip code in the form, and have the city and state come up
automatically.

I have two tables:

Table 1 (14 fields): Customer Name, Address, City, State, Zip,
Preferences, etc
Table 2 (3 fields) : City, State, Zip

The form right now is completely based on Table 1. The data entered
in the form goes into Table 1. How can I get the form to look up City
and State after the Zip is entered, and enter the new data into Table
1?

Thanks for your help.

AM


Nov 12 '05 #4

Thanks Wayne for the response. I tried typing the command into the
after update event but kept getting errors. Am I missing something
here?

I typed the following into the afterupdate event of the Zip Code
Textbox:

State = DLookup("State", "Table2", "ZipCode = '"&ZipCode"'")

Am I doing something wrong with the spaces? The name of the ZipCode
field in both tables is "ZipCode" and the name of the State field in
both tables is "State".

I hope I can get this!
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #5
Steve E. has a very good suggestion that you may want to consider. The
procedure would be the same, just the name of the table would be different.
State = DLookup("State", "Table2", "ZipCode = '"&ZipCode"'") For starters, you are typing this into the event procedure in the VBA
window, not directly into the Properties sheet, correct? Next, the syntax at
the end is off a little. You need to concatenate the zip code and the quotes
together so that the zip code gets passes as a text value (zip codes are
normally text, if you have them as number, you would need to change this).

State = DLookup("State", "Table2", "ZipCode = '" & ZipCode & "'")

Also, it appears that your textboxes have the same name as the fields they
are bound to. This may not cause you a problem here, but is can cause a
problem in some cases. I would recommend renaming them. Every object in your
database should have a unique name. The easiest way to rename them yet keep
them meaningful is to put a prefix on the name, such as txt for a textbox.
That would change the name of the State textbox to txtState. For a listing
of commonly used prefixes, check this link.

http://www.mvps.org/access/general/gen0012.htm

--
Wayne Morgan
Microsoft Access MVP
"AS Mann" <ta******@aol.com> wrote in message
news:40*********************@news.frii.net...
Thanks Wayne for the response. I tried typing the command into the
after update event but kept getting errors. Am I missing something
here?

I typed the following into the afterupdate event of the Zip Code
Textbox:

State = DLookup("State", "Table2", "ZipCode = '"&ZipCode"'")

Am I doing something wrong with the spaces? The name of the ZipCode
field in both tables is "ZipCode" and the name of the State field in
both tables is "State".

I hope I can get this!
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old...
6
by: Kurt A. Kaylor | last post by:
Hey, I am trying to get some code I have written to work. Runs well until I make a request. The I get some problems with PHP related to an SQL statement. Here are the errors :Warning:...
2
by: Ian DeRock | last post by:
I'm fairly new to XML. As I can see it, XML is a way to organize data like in a table in a RDB, or the RDB itself. I have used XML in application data, but did not design the actual XML. I...
25
by: koray | last post by:
hi everyone, in my form i have to take some date information in dd-mm-yy format. but i don't want user to use tabs while typing. for example s/he should simply type 280104 but 28/01/04 must...
5
by: CaliSchmuck | last post by:
I think this is probably simple, but I'm having a problem figuring it out. I have a form that is used to enter data. I want users to be able to enter a zip code in the form, and have the city...
11
by: my-wings | last post by:
I think I've painted myself into a corner, and I'm hoping someone can help me out. I have a table of books (tblBooks), which includes a field (strPubName) for Publisher Name and another field...
2
by: Shawn Yates | last post by:
I am creating a Zip Code search tool. I have a Table with every zip code and its corresponding city and state. I have also created an input table that allows the user to input cities and states....
6
by: pagina21 | last post by:
I am a true beginner in Access and coding. I am creating a database with facility information and I want to use the address of a specific facility to display a map on my form or at least open a...
5
by: samdev | last post by:
I have created two combo boxes in a subform.... For example 1. Combo Box State 2. Combo Box City 3. When a state from the Combo Box State is selected, the City combo box updates to reflect...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.