Sometimes you have to overhaul your table to such an extent exporting to, say Excel--and reimporting back into Access once you've "cleaned it up"--becomes the necessary thing to do. Trouble is, Access doesn't like for the user to import data with pre-existing autoid values; it likes to assign new ones at the time of importing.
I had two instances of this, one in February 2001 and the other in September 2002. In the 1st incident, I had a table named "front_end" with a field called "project managers." This field linked to another table via an "autoid" type of value; this other table had a list of project managers as well as other fields which had nothing to do with project managers. I came to see that I would need a table for project managers all by itself, and so I wanted to create such a table with the original autoid values intact. This was necessary because the "front_end" linked to the project managers through this "autoid" value, and if they were to reset themselves in the typical "1.2.3.4.5.6" pattern throughout (gaps in the autoid numbers existed in the current layout), these links would be ruined.
The 2nd scenario--which I will use in the steps outlining my solution--was I had a table named "vendor_quotes," and this linked to a "vendors" table via an "autoid" value. The "vendors" table was highly "cleaned up," and doing this required exporting it to Excel 1st and then reimporting it again. Once again, if I were to do this in a "normal" manner, the original sequence of autoid values (which was something like "2.3.4.6.7.9.12.13.14") would be lost and reset back to "1.2.3.4.5.6." Again, this would create a problem since "vendor_quotes" was linked to "vendors" (the table being overhauled) via these values.
One common way a user may try & overcome this is to designate the "autoid" field's type in the new "target" table as being a "number" type rather than a "autonumber" type, because if a user attempts to copy & paste values into an "autonumber" type of field, Access won't allow this. As anyone knows, Access doesn't allow the values of an "autonumber" type of field to be changed; therefore, it stands to reason, why not just change the "autoid" field's type to a standard "numeric field", so its values can be changed (that is, so the user can paste the original values into the field)? Then, after the values have been pasted with the original values intact, just change the "autoid" field back to its original "autonumber" type.
However, that doesn't work because Access doesn't allow a user to change a "numeric" type of field to an "autonumber" type of field if there are already values present, as would be the case once the user has pasted. (The same thing probably holds for changing a "text" type of field to an "autonumber" type of field as well.)
Another way would be to leave the "target" table's structure with the "autoid" field having the normal "autonumber" type attributes, and copy/paste the data without the original autoid values. Doing this, however, results in the autoid sequence resetting itself back to "1.2.3.4.5" etc throughout the entire table.
The way to fix this is to use an append query--a query that allows the user to add records from one table to another. Let me use the 2nd scenario as a case study to better explain this.
I have this table named "tbl_vendors" which I have exported to Excel and cleaned up. The Excel file has column headings which double as field names.The original table is still in Access. Here is what I would do:
In summary, what we are going to do is establish a "source" table--with the data now "cleaned up" and the autoid values intact--and also establish a "target" table which will be the table ultimately used. The "source" table will have its autoid field set as a regular numeric field, even though its name is still "autoid" and the values are intact. Ultimately, the "target" table will have these same values intact with the "autoid" field set as a normal "autonumber" type in its attributes, which is ultimately what we want to have happen.
Here are the steps:
|
-----Original Message-----
From: Eldon Ferran de Pol [mailto:eldon@ferran.freeserve.co.uk]
Sent: Monday, February 05, 2001 12:29 PM
To: Larry H
Subject: Re: resetting autonumbers
Hi Larry,
An append query will allow you to do this.
If you define your new Project Manager table with an autonumber field and
then append the Project Manager records into the table, including the
existing autonumber field into the new table's autonumber field, they will
keep their values.
Eldon.
----- Original Message -----
From: "Larry H" <larryh@appliedimage.com>
Newsgroups: microsoft.public.access.tablesdbdesign
Sent: Monday, February 05, 2001 6:30 PM
Subject: resetting autonumbers
> I realize that resetting autonumbers is in general not a good idea, but
> I have a bit of a special case here.
>
> I have a table called FRONT END with one of the fields being
> titled "project manager." This field is actually a number that refers
> to an "autonumber" of the matching name in another table. This other
> table actually contains many other fields besides project managers and
> I have now come to see the need for project managers to need a table of
> their own.
>
> So what I am trying to do is create a new project managers table, have
> an AUTONUMBER field, AND have these numbers be the same as the
> autonumbers were originally. That way, I won't have to go back to the
> FRONT END table and change the numbers in that field to reflect any new
> numbers.
>
> This doesn't seem to work because if I try & change a "number" field-
> type to an "autonumber" field-type, Access won't let me. I tried
> pasting the data in Excel and then importing, this also doesn't work.
>
> Is there any way to prevent having to re-enter the numbers in the FRONT
> END table to match new "autonumbers," or am I stuck?
>
> Larry R Harrison Jr
>
>
> Sent via Deja.com
> http://www.deja.com/
Note: I have also found one can do this by copying/pasting the tables, and saying "structure only." This works if you're creating a new blank copy of the database and want to give the new user "fresh" autoids so that their intial entries don't start out with large autoid numbers.