473,385 Members | 1,620 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,385 software developers and data experts.

I need city and state to populate after I enter the Zip Code in Access

I have an Access DB that I'm looking to have the City, State, and some other info auto populate after I type the Zip. I am VERY VERY new to Access and am teaching myself. I don't know VB and would need to be walked through step by step. Any help would be possible.

Thanks
Jul 26 '07 #1
15 9347
pbmods
5,821 Expert 4TB
Heya, imnotsmart. Welcome to TSDN!

I'm going to go ahead and move this thread to the Access forum, where our resident Experts will be better able to help you out.
Jul 26 '07 #2
Rabbit
12,516 Expert Mod 8TB
Is it safe to assume you have a table listing all cities, states, and zip code?
Jul 26 '07 #3
Is it safe to assume you have a table listing all cities, states, and zip code?
Yes. I have the table with all the Towns, Cities, Zips and other info I need.
Jul 31 '07 #4
Rabbit
12,516 Expert Mod 8TB
In the after update event of the zip code control you'd have something along the lines of:

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtZip_AfterUpdate()
  2.    txtCity = DLookup("City", "tbl_ZipCityState", "Zip = " & Me.txtZip)
  3.    txtState = DLookup("State", "tbl_ZipCityState", "Zip = " & Me.txtZip)
  4. End Sub
  5.  
This assumes zip is a numeric data type.
Jul 31 '07 #5
The Zip is a text data type (Zip codes in NJ start with 0. If its numeric the 0 gets dropped). The table is called City. The fields are City, State, Zip. So based on what you posted before, I tried this:

Private Sub Zip_AfterUpdate()
txtCity = DLookup("City", "tbl_City", "Zip = " & Me.txtZip)
txtState = DLookup("State", "tbl_City", "Zip = " & Me.txtZip)
End Sub

When I go back to the form, I get the following error.

Compile error:
Method or data member not found

.txtZip on line 2 is highlighted in blue and the first line is highlighted in yellow.
Aug 1 '07 #6
Rabbit
12,516 Expert Mod 8TB
If Zip's text then you'll need to do:
Expand|Select|Wrap|Line Numbers
  1. "Zip = '" & Me.txtZip & "'"
  2.  
txtZip, txtCity, and txtState are in reference to the controls on your form, I doubt that's what you named them so you'll have to change those to match.
Aug 1 '07 #7
Thanks!! I played with it a little and got it to work.

Now, another question. I have yes/no buttons associated with each town and a number. Is the code the same or does it change.
Aug 1 '07 #8
Rabbit
12,516 Expert Mod 8TB
Thanks!! I played with it a little and got it to work.

Now, another question. I have yes/no buttons associated with each town and a number. Is the code the same or does it change.
I'm not following, can you go into more detail?
Aug 1 '07 #9
Nevermind, I figured it out.

But I have another question. I need the info that populates in the City, State and Zip field to fill in City, State, and Zip fields in another table. Don't know if this is possible.
Aug 1 '07 #10
Rabbit
12,516 Expert Mod 8TB
Nevermind, I figured it out.

But I have another question. I need the info that populates in the City, State and Zip field to fill in City, State, and Zip fields in another table. Don't know if this is possible.
You mean into an additional table? You'll need to use DoCmd.RunSQL "INSERT INTO ..."
Aug 1 '07 #11
Yes, into an additional table called People.
Aug 1 '07 #12
Rabbit
12,516 Expert Mod 8TB
Ok, then try out what I suggested in post #11.
Aug 1 '07 #13
Not sure how to do it. Can you give a little more. Here is some more info.

After the City, State, and Zip are entered for a Person in my form, I need the City, State, and Zip to also show up under that Person in a different table.
Aug 2 '07 #14
Rabbit
12,516 Expert Mod 8TB
Not sure how to do it. Can you give a little more. Here is some more info.

After the City, State, and Zip are entered for a Person in my form, I need the City, State, and Zip to also show up under that Person in a different table.
What you'll want to do is, in the after update event of each of the fields, check that all 3 fields are populated, i.e. not null. Then you want to check to see if a record already exists in the other table. If it does, you use DoCmd.RunSQL "UPDATE SQL String". If not, you use a DoCmd.RunSQL "INSERT INTO SQL Append String"
Aug 2 '07 #15
I found this interesting and was wondering if it could be expended a bit.

My table of zip codes has Primary City Name [PrimaryCityName] and Acceptable City Names [AcceptableCityNames]. I'd like for the code to change the [City] control on the form to an option drop down showing the alternative Acceptable City Names that the user could then select from. The acceptable city names are stored comma separated so sometimes they will have multiple acceptable city names to select from. Both are Short Text data types.

Here is my code pulling just the three things I want to use but I don't know how to code the options part of it.
Expand|Select|Wrap|Line Numbers
  1. Private Sub ZIP_Code_AfterUpdate()
  2.  
  3.    City = DLookup("PrimaryCityName", "tblZipCodes", "ZipCode = '" & Me.[ZIP Code] & "'")
  4.  
  5.    State = DLookup("StateCode", "tblZipCodes", "ZipCode = '" & Me.[ZIP Code] & "'")
  6.  
  7.    Country = DLookup("Country", "tblZipCodes", "ZipCode = '" & Me.[ZIP Code] & "'")
  8.  
  9. End Sub
Thanks,
Terry
Oct 5 '16 #16

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...
9
by: Mike McGee | last post by:
I am new to database apps, but I am making a db with access 2002. Here is what I have and what I would like for it to do. tblCustomers = holds customer info (Name, Address, City, State, Zip,...
0
by: Namratha Shah \(Nasha\) | last post by:
Hey Guys, Today we are going to look at Code Access Security. Code access security is a feature of .NET that manages code depending on its trust level. If the CLS trusts the code enough to...
8
by: Sree | last post by:
hello people, Can any body give me the code or the basic logic to enter and also access data from a Database management system using C?...also tell me the actuall syntax to run an .exe file using...
5
by: Simon Hart | last post by:
Does anyone know the standard code access permission to be able to manipulate a process using the Process class? Thanks Simon.
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...
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. ...
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...
3
by: rizwanrazzaq | last post by:
Hi friends here is my coding.. but i m facing one problem .. i used both mathod SQL mathod and open Record Set. but in both i m getting error massage can anyone help me out regarding thi. Please...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.