How not skip over a primary key.

I have a form which has a table as its record source.  the form also has a sub-form.  If the user enters data in the main form and then does not enter any data in the subform we have the record being deleted when the form is closed.  This is by design.

But then of course the record number is lost and the next record number skips over the deleted one.  We don't want to have the record number skipped.

Can this be done somehow?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Why are you creating a subform record via code?  The subform record should not be created unless the user starts typing into it.  NEVER dirty a record before the user does.  It is poor practice and leads to all sorts of issues.

As to gaps in the autonumber, they are unavoidable and in no way would cause a problem.  If you have some other business rule you are attempting to implement such as generating a check number where gaps are simply not allowed, then you cannot use an autonumber.  You have to create your own sequence number and you have to handle backing it out if necessary.

The reason the gaps appear in your case is that when you dirty the subform record, Access generates the autonumber.  In the mean time, some other user could enter a record and use the next autonumber.  If your record doesn't get saved, you end up with a gap and there is nothing you can do about it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteveL13Author Commented:
We are not creating a subform record via code.  If I implied that I sure did not mean to do so.  But thank you for the information.  I think we'll have to live with skipped PKs.
I reread the question and originally I thought you were deleting subform records but now I think you mean that you are deleting main form records if no subform records were created.  OK, that makes more sense but the autonumber gaps occur due to what I said.
SteveL13Author Commented:
Yep.  Thanks again.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.