Question

Before you think this is a question that has already been answered, hear me out.

I inherited an Access MDB file. It has 2 tables (actually 4 but I'm only really concerned with 2). One is a member table with an AutoNumber field. The second table has the same fields but the ID field is simply Number (not AutoNumber). This second table gets the names of people when they "retire".

The problem now is some people want to return. I can't copy them back in because they will get a new ID number and all of the other report data (that I didn't mention before) is keyed to their original ID number which is still unique between the two tables.

What I think I'd like to do is temporaily turn off the AutoNumber field long enough to allow me to merge the data from the "retired" table, then turn AutoNumber back on. But Access won't let me do that because the AutoNumber ID is tied to other tables and various reports. (I guess I do care about the other tables.)

This answer is close, Adding records with old ids that were generated using auto number in access, but focuses on 1 row. I have plenty. Same with this answer: Keep value of autonumber column when importing into Microsoft Access database.

I'm thinking the second answer is really close, but I don't know how to use docmd.RunSQL.

If this is simple and I'm just missing the obvious, I'm willing to admit being a NOOB with Access.

Was it helpful?

Solution

Access will let you INSERT a row with a number for an autonumber field as long as the number you're inserting doesn't conflict with any of the existing values. And since "their original ID number which is still unique between the two tables", it sounds like that is your situation.

Consider these 2 tables:

tblMembers

id fname
 1 Anne
 3 Cathy

tblRetired

id fname
 2 Bob
 4 David

This INSERT statement (the Access query designer calls it an "append query") will add the tblRetired rows to tblMembers.

INSERT INTO tblMembers ( id, fname )
SELECT r.id, r.fname
FROM tblRetired AS r;

This is tblMembers after executing that INSERT ...

id fname
 1 Anne
 2 Bob
 3 Cathy
 4 David
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top