MDB file and Primary Keys

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When I use the ADD button on the navigator, it creates a primary key based on
the dataset, lets say 9. Whne I go to save the record, Access won't take it
because it it not the next key available. Even though 9 does not have a
record associated with it now, it once did and was deleted. I think i this is
normal op for Access.

How do I resolve this issue. Any ideas how the ADD button can get the
correct next available primary key from the table?
 
Chris said:
When I use the ADD button on the navigator, it creates a primary key based
on
the dataset, lets say 9. Whne I go to save the record, Access won't take
it
because it it not the next key available. Even though 9 does not have a
record associated with it now, it once did and was deleted. I think i this
is
normal op for Access.

How do I resolve this issue. Any ideas how the ADD button can get the
correct next available primary key from the table?

Have you defined the primary key as an autonumber in the database? If so,
you should not be trying to assign a value under any circumstances. Just let
Jet assign the next available number.
Sequences (autonumber type fields) are never guaranteed to be sequential in
a given table because of the delete situation you mentioned and other
circumstances such as transactions rolled back. If you need a primary key
field to actually be sequential, or you want to go back and reuse numbers
vacated by deletes, etc., you'll need to do it programmatically and not use
autonumber.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top