473,614 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need HELP / Increment ID (number) for each unique text string

Below is an earlier post to an Excel Group..
....but I thought that there might be a way to do this in Access
by importing data and then creating append and/or update query. I would
most certainly need to use the right type of table join and criteria in
the query to perform the task, and don't find myself an expert or up to
par as far as I'm concerned.

*************** *************** *************** *************** *******
Hello everyone,
I've run into a wall. I have a 4 column list of data.
Column 1 has a list of US Cities.
Column 2 has a list of Unique IDs for each State in Column 3.
Column 3 has a list of US States.
Column 4 has a list of US Zip Codes for the above entities.
Ex.
CITY STATE_ID STATE ZIPCODE
Akiachak 1 Alaska 99551
Akiak 1 Alaska 99552
Akutan 1 Alaska 99553
Abbeville 2 Alabama 36310
Adamsville 2 Alabama 35005
Addison 2 Alabama 35540
(Etc. With a total of 28,758 rows of the same.)
The following is an example of what I need done.. and I have decided
that manually doing this would be a rather mundane PITA.
CITY_ID CITY STATE_ID STATE ZIPCODE
1 Akiachak 1 Alaska 99551
2 Akiak 1 Alaska 99552
3 Akutan 1 Alaska 99553
4 Anchorage 1 Alaska 99508
4 Anchorage 1 Alaska 99515
4 Anchorage 1 Alaska 99518
5 Abbeville 2 Alabama 36310
6 Adamsville 2 Alabama 35005
7 Addison 2 Alabama 35540
8 Anniston 2 Alabama 36205
8 Anniston 2 Alabama 36206
8 Anniston 2 Alabama 36201
My question is this, is there an easier way to do this...
programmaticall y or via formula? If so, can someone please
give me a hint in the right direction?
I'm guessing it would need to begin with Row 2 and first lookup Column
3 (StateID) then begin to read Column 2 (City - text string)If it is
found to be UNIQUE when comparing to the previous row's text string AND

(very important - StateID remains the same value) THEN Column 1
(CityID) should be assigned a value beginning with 1.
If it is found to be a duplicate string then it should retain the
(CityID) value of the previous row. It then repeats until it finds no
data (NULL). I'm guessing that if this is done with code it will
contain a FOR, IF, NEXT statement and maybe a DO WHILE or two.
Thanks,
Robert

Nov 13 '05 #1
1 2835
Probably your best bet would be to import your spreadsheet into Access
and then create a new tables to store the results in the way you are
looking for. I would suggest making a States table and storing the
StateID and State in that table. Then make another table with the
CityID of type AutoNumber, City, StateId. Then make a third table with
CityId and ZipCode.

You now need three queries. Create a new query in design view and
select the table that you imported to Access. Right click in the gray
area and select Properties. On the row labeled Unique Values, put Yes
and close the Properties window. Now Double-click on StateId and
State. They should appear in two columns below. In the menu bar,
click Query, then Append Query. You want to Append To your States
Table. Run the query by clicking Query, Run in the menu bar, or the
icon with the red exclamation point in the tool bar.

Make another append query from your imported table only this time
append the City and the StateID to your Cities table.

Make a third Append Query from the imported table. This time you are
going to select the imported table and the Cities table. You want to
link the City Names from each table together and the StateIDs from each
table together. You link them by selecting one and dragging it over to
the other. Now append CityId and ZipCode to the ZipCode Table.

To view the data in the format you are wanting, make a query that links
the Cities, States, and ZipCodes tables.

Hope that helps you!

CITY_ID CITY STATE_ID STATE ZIPCODE
1 Akiachak 1 Alaska 99551
2 Akiak 1 Alaska 99552
3 Akutan 1 Alaska 99553
4 Anchorage 1 Alaska 99508
4 Anchorage 1 Alaska 99515
4 Anchorage 1 Alaska 99518
5 Abbeville 2 Alabama 36310
6 Adamsville 2 Alabama 35005
7 Addison 2 Alabama 35540
8 Anniston 2 Alabama 36205
8 Anniston 2 Alabama 36206
8 Anniston 2 Alabama 36201
My question is this, is there an easier way to do this...
programmaticall y or via formula? If so, can someone please
give me a hint in the right direction?
I'm guessing it would need to begin with Row 2 and first lookup Column
3 (StateID) then begin to read Column 2 (City - text string)If it is
found to be UNIQUE when comparing to the previous row's text string AND

(very important - StateID remains the same value) THEN Column 1
(CityID) should be assigned a value beginning with 1.
If it is found to be a duplicate string then it should retain the
(CityID) value of the previous row. It then repeats until it finds no
data (NULL). I'm guessing that if this is done with code it will
contain a FOR, IF, NEXT statement and maybe a DO WHILE or two.
Thanks,
Robert


Nov 13 '05 #2

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

Similar topics

4
2666
by: Duffey, Kevin | last post by:
I don't know if jdbc/java code requires this, but when I use two gui admin tools I found, and I insert a row into the table using their row editor feature, both require me to enter a number for the Serial type. I thought this type was used to auto-increment an id field and that I would not need to enter anything into it? Basically we need the normal indexed ID field for each table, and we want it to auto-increment. The serial shows a function of...
1
1900
by: Anthony Esochaghi | last post by:
I need some constructive input to be able to finish my program. I have a field called (1) DateRec, another (2) Municipality and another (3) Type. These three fields invariably will automatically generate a string of number for another field that is called FileNumber. This FileNumber is already the Primary Key in the program. The (1) is the date received, that is the date the application of the client was received. (2) The...
11
4481
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any AutoNumber* fields in them. Correct me if I'm wrong, but I'm assuming this means that I cannot now alter these existing Access tables and change their primary key to an "AutoNumber" type. If I'm right about this, I need some suggestions as to the...
4
2190
by: naknak4 | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will implement all three techniques as programs. In these programs, as well as solving the problem, you will also measure how long the program takes to run. The programs are worth 80% of the total mark. The final 20% of the marks are awarded for a...
6
2116
by: naknak | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will implement all three techniques as programs. In these programs, as well as solving the problem, you will also measure how long the program takes to run. The programs are worth 80% of the total mark. The final 20% of the marks are awarded for a...
3
5607
by: sunbeam | last post by:
Short Description of the Project: we developed a e-learning system for our students. each student has a unique username/password to view the modules he/she should view and nothing more. since we want to give them the opportunity to run these modules from home as well, we are trying to get the USERNAME/COMPUTERNAME as well, so the students, when they sign up for the modules, they can ONLY run the modules fromhome PC. We found a nice...
0
7106
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past the due date 10% of the grade is taken off. I think I'm coming down with the flu and my brain is just not processing this assignment. Here is the assignment: Modify the Inventory program by adding a button to the GUI that allows the user to move...
1
1609
by: Studiotyphoon | last post by:
HI, I have two tables which currently have Autonumber fields which are used to create a unique number to identify an invoice for each table. Instead of having two unique numbers I'm after only one. My thinking behind this is to Create a text file with a number in it.
11
4353
by: blunt | last post by:
trying to write a program to write the configuration files for a load of wireless access points. i've never been a good programmer and haven't done any for nearly a decade so have obviously made some mistakes, i'm using cygwin on a windows pc and it seems that some functions cause stack overflows so am using fgets instead of fgetc (don't know y it solved the problem but that part is working). my problem now is that i am reading strings a few...
0
8182
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8130
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8279
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6088
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5540
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4127
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2568
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 we have to send another system
1
1747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1425
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.