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

Restore autonumber field? or use DMAX in append query?

Hi,

I’m desperately looking for some help… I maintain a Contacts database which has about 27,000 records. It was initially set up for the field Contact_ID to be an autonumber (also my PK), and this has worked great for a few years now. Earlier this week we noticed that we had some duplicate Contact_ID’s (about 160 of them), which I would have thought to be impossible. No idea how that happened, but it seemed to start last week. I needed to correct this problem, obviously, so I changed the autonumber field to be a number field (which I sincerely hope wasn’t a huge mistake!) so that I could edit the values and assign unique ID’s to each record. I naively thought I could fix the problematic ID’s and then change the field back to be an autonumber – apparently not.

I then added the DMAX+1 function to my forms so that when someone adds a new contact, they get assigned a Contact_ID. I thought my problem was solved – until today when I needed to import a few hundred contacts by doing an append query (and I have a need to do this about once a month). I can’t leave my PK empty, so I thought a workaround would be to put a 0 or 1 in the Contact_ID field, and then run a secondary query that would change the value in that field to be the DMAX+1 result – similar to what is described in this related article:
http://bytes.com/topic/access/answers/694370-inserting-new-unique-sequence-numbers-without-autoseq
But that doesn’t work, either. When I attempt to run the query, I get the error that “Access set 0 fields to Null due to type conversion failure and didn’t add the records to the table due to key violations”.

I’m really wishing I still had my autonumber field, but I’m not seeing any way to get that back. I know I could copy the table and reimport the records back in to a table with the autonumber field, but that won’t work because I definitely have some skipped ID’s (eg, someone started adding a record and decided not to, so the record was just the ID number – I’ve periodically deleted these records from the table). I can’t assign new ID numbers to each contact because these ID’s are tied to mailing lists and other tables.

Could anyone give me advice with this? Either a way to make my append query work with assigning sequential numbers in the Contact_ID field, or a way to recreate an autonumber field and match things up the way they are?

Thanks a million for any recommendations!
Jan 20 '12 #1

✓ answered by dsatino

I'm sure you'll get other responses as well, but here's what I think the easiest thing to do is:

1.Recreate your table without any data. Set your ID field to the autonumber data type.
2. Re-populate the missing ID's from your current table.
3. Write an append query to your new table using your old table as the source. Be sure to sort the ID field in ascending order.

This should get you what you want. Validate that it did, then delete your old table and rename the new one to the old one.

3 2711
dsatino
393 256MB
I'm sure you'll get other responses as well, but here's what I think the easiest thing to do is:

1.Recreate your table without any data. Set your ID field to the autonumber data type.
2. Re-populate the missing ID's from your current table.
3. Write an append query to your new table using your old table as the source. Be sure to sort the ID field in ascending order.

This should get you what you want. Validate that it did, then delete your old table and rename the new one to the old one.
Jan 20 '12 #2
Thank you! I did this and it worked perfectly - solved all my problems. I appreciate the response!
Jan 23 '12 #3
NeoPa
32,556 Expert Mod 16PB
Katie Howard:
I appreciate the response!
Many posts are appreciated. If they can also be considered correct/most helpful responses to the question of the thread then you can show this by selecting them for Best Answer. I believe this one (Post #2) fits the criteria ;-)
Jan 23 '12 #4

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

Similar topics

1
by: Rose | last post by:
I have an access 2000 database. In it I have a table OPEN Items which has a field Issue that is setup as a MEMO field. I am trying to append information from another table with the same setup,...
0
by: Andy_HR | last post by:
1. question when i have custom autonumber field... like Nz(DMax("ClanID", "tblClanovi")+1 how can i make it try again if someone else pressed the save button and that namber is already taken,..??...
2
by: Ray Holtz | last post by:
I have a form that shows a single record based on a query criteria. When I click a button it is set to use an append query to copy that record to a separate table, then deletes the record from the...
5
by: marko | last post by:
I would like my autonumber field to start at 100000. How can i do that?
3
by: a_masselink | last post by:
It doesn't append anything to the primary key (autonumber, long integer), only to all the other fields. Even if I set all the fields to allow zero length: yes, indexed: no and required no. All the...
7
by: pltmcs | last post by:
I am trying to generate some records from one table into another. The problem is that the new table has an autonumber field (PID). The PID is part of the primary key since it is possible to have...
4
by: reprosser | last post by:
I have created an append query in my MSAccess front end to the linked table in SQL Server. There is an ID field which is common in the query that is type autonumber/identity. If I do not include the...
2
by: Richard Sherratt | last post by:
I've inherited a system that was designed by someone with no understanding of database design. From the logical design point of view, there is no logical design. The physical design is a nightmare....
6
by: Amy Badgett | last post by:
I need to create an Autonumber field in a query I am currently running. The query right now calls fields such as names, addresses, phone numbers and is distinct on the client id. Each time I run the...
4
by: Amy Badgett | last post by:
I have figured out that there is no easy way to create an autonumber field in a query, but that there is a way (supposedly) to create an autonumber field in a table or rather, there is already an...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.