473,468 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Zip code back fills city and state

1 New Member
Looking to use VBA code to back-fill city and state from a zip code. For the main table, I have peLoc1Zip (short text), peLoc1City, peLoc1State. All short text.
In the table 'zips' I have an autonumber, Zip, City, State - All are short text.
This is what I've tried so far:
=========================
Expand|Select|Wrap|Line Numbers
  1.  Private Sub peLoc1Zip_AfterUpdate()
  2.  
  3.        Zip = "'" & Me.peLoc1Zip & "'"
  4.  
  5. peLoc1City = DLookup("City", "Zips", "Zip = " & Me.peLoc1Zip)
  6.  
  7. peloc1State = DLookup("State", "Zips", "Zip = " & Me.peLoc1Zip)
  8.  
  9. End Sub
===============================
Second part of the problem is there are some zipcodes that have multiple towns. For instance, my Town (Southbridge) is also listed as Globe Village, Sandersdale, Southbridge, Southbridge Center, W Dudley, West Dudley (sorry just copy and pasted the results). To handle this, I would like to have a combo box populated with the results of the zipcode.

I'm at a complete loss and would appreciate some help. Thanks in advance!
Alan
Jan 4 '14 #1
2 1838
zmbd
5,501 Recognized Expert Moderator Expert
kb1pwr:
1)Please format you script using the [CODE/] button.

2)Respectfully, normally, only one topic per thread will be addressed, this is a site/thread requirement:

3)You've not told us what is wrong with your code, version of office/access

4)Normalizing your database will help you with both aspects of your question(s): > Database Normalization and Table Structures.

Because you've left some details out, such as (3), I'll offer you some advice to consider:

A properly normalized database will not store the same information in multiple tables unless there is a need for auditing or other special cases.

IMHO: What you should consider is the following database scheme:=

tbl_zipcode
[zipcode_pk] autonumber
[zipcode_main] text(20)

One might be tempted to use the zipcode as a primary key as it shouldn't be repeated. So long as you are dealing with the USA that will hold true for the forseeable; however, if you need to add Canada or other contries then you're in trouble as these are not numerics and numerics are easier and faster.

Tbl_State
[state_pk]autonumber
[state_fullname] text(25)
[state_abrv] text(5)

Should be obvious.

Tbl_City
[City_pk]autonumber
[City_name]text(50)

Now you can either use these as foriegn keys in an addressbook type table or do the following:

tbl_cityloc
[cityloc_pk] autonumber
[cityloc_FK_city] numeric(long)1:m with tbl_city
[cityloc_FK_state] numeric(long)1:m with tbl_state
[cityloc_FK_zipcode] numeric(long)1:m with tbl_zipcode

Now you would only use the [cityloc_pk] to refer say, Los Vegas, NV; or Greenville, AL; Greenville, AK; etc... instead of repeating the information a ton of times.

Once you have this tbl_cityloc, you can build a query that has that pulls the stuff from the related tables for a nice human readable text and yet the value of the control is just the [cityloc_pk]... you can also build cascading comboboxes and other filters that will make your searches easier.

Now this is just one way to do what I think you are after.

If you are a very new user to Access, VBA, database design, please let me know and I'll pm you a list of tutorials and references that will help you get out the kiddie pool and into the deepend in fairly quick time.
Jan 4 '14 #2
NeoPa
32,556 Recognized Expert Moderator MVP
As Z says, focus on getting the design right and the rest falls neatly and easily into place.

Numerics are always good for a PK, but any short text that is demonstrably unique and doesn't exceed eight characters can be equally as good. In general, shorter (that take up less space in RAM) index values are better because more of them can fit into the same sized chunks of memory and so can be accessed without having to return to the (relatively much slower) Hard Disk Drive (HDD) to get them.
Jan 5 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: B. G. Mahesh | last post by:
hi In the registration form I have city, state, country fields. I was wondering if there was a database available on the net which has the list of states in each of the countries. That way when...
1
by: greg.scharlemann | last post by:
Does anyone know where I could find a complete city and state database for MySQL? I've looked at the Zip Code data on the census website, but don't know the best approach to get a .dbf file into...
10
by: somaskarthic | last post by:
Hi In my php page , there is a user registration form. Here the user has to select the country, state, city from the drop down box. How this can be handled in php? If a country is selected in a...
2
by: colleen1980 | last post by:
Hi: Can any one please tell me how do i separate city state and zip. I ask this question in previous post. But when the city name is in two words it mess up my values otherwise it works. ...
2
by: san | last post by:
Hello, i am in great trouble. I want to revert back to original state of database before i performed restore database on my sql server 2K Database. Accidently i didn't take backup of my Database...
6
by: cfish | last post by:
I'm trying to script my contact page and I have everything the way I want it however I cannot get my script to output Address, City, State, Zip & Phone Number when I get a email. It will output...
4
by: cliffcoder2 | last post by:
hi, i m pappu jaiswal,i want to display city and country where our site will open so plz provide me appropriate code for this. thanks
1
by: sahilansari | last post by:
I have a table in MYSQL database... With Country & it's corresponding States. Say i select US from the dropdown option it should automatically show all the states in US from a database file. ...
1
by: patrioticcow | last post by:
hello. i have 3 tables "city" containing id, city, state_id and "states" containing id, states and "table" containing a city field (INT 11) what i want to do is to select a state then select a...
1
by: PreethiGowri | last post by:
I have coded to find the ip addresses of my network. Now i need to code for finding the city,state,country, latitude, longitude with reference to the IP address, How do i do it? Is there any library...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.