Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clear filled NewRecord-Form without losing RecordID

Status
Not open for further replies.

Snamelisch

Programmer
Aug 30, 2005
2
NL
Hello, I am Marc Schillemans (Dutch). I am an experienced programmer in Visual Basic, but I can't solve the next problem.

Question in short: I like to clear a partially filled form of new record without losing the current Record ID.

Short description:
A user enters data in a form, but while doing this decides he wants to stop. He then closes the accessform or goes back to another record. The form is cleared, but the recordID is lost. It is not a real problem, but the users dislike it very much and I think there is good solution for this situation.
(By the way: I don't want any workarounds like using a counterField in the Recordsets)

Long description:
I use an accessform to fill data into my database. Because I needed to add some extra check-ups I choose to take control over the moving between record, deleting and creating new records. So there are 'Home-made'-buttons (Next, Previous and New) on the form.
On the form there is also a control (lets call it RecordID-control) that shows the current RecordID (in this case a number). This is very handy for the users. As normal I use Autonumbering for handeling the RecordID-numbering.

If a user enters data in one of the controls. The new RecordID is shown in the RecordID-control (as it should). For some important reason the can user decide to stop entering data and do something else. He can look on other records (using the back and forward buttons) or even close the access-application.
To prevent data-corruption the newly created record must therefore be cleared.

Now I simply want to do this without losing a RecordIDNumber, so the numbering stays logical.
There must be a way to delete the new record, without losing the ID. Or even better: Prevent the newly created record to update to the record, as if it never excisted.

As written before, I think the solution should be possible and it is probably extremely simply, but I really cannot find it.

Thanks for answering my question.

BSc Marc Schillemans, Crams, The Netherlands
 
If you have multiple users however, let's say user A and user B, if user A starts entering a record, and let's say it's autonumber is 50, and then user B starts entering a record, this record gets autonumber 51.

If user A deletes the record, even though it hasn't been saved, you will permanently lose autonumber 50, as the highest number is already 51.

In such situations, if it's important that an ID is sequential, you can use a separate table that just supplies a sequential number OR any previous number that's been deleted.

It's generally not good practice to have an ID that has any true relevance to a user, unless really necessary. Is there any reason that your users should even see the ID?



Max Hugen
Australia
 

Sorry, if you base this RecordIDNumber on an autonumber it will not be be available for the next record, whether you delete the record or use Me.Undo! That's one reason why autonumbers should not be used in this manner. They're intended to be used behind the scenes, as it were, by Access. A number of things will cause autonumbers to be "lost." If you want to RecordIDNumber to behave in the manner you describe, you either have to create your own number incrementing scheme (using DMax to find the next number) or use an unbound form for data entry. If you use an unbound form, the autonumber won't get generated until the record is written to the table.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
If you delete a new record, the same Autonumber id will be available for the next record
Absolutely FALSE.
 
hmmm... OK, my apologies, the autonum won't be avail if a new record is undone etc. Guess I haven't used an incremental autonum for a very long time... mine are always randomized, so that others are never tempted to use it for anything other than an absolute record identifier.

Max Hugen
Australia
 
There is a FAQ somewhere on this forum that shows you how to make your own incrementing number field. It temporarily locks the table so that duplicate ID's are not created. A very similar method is shown in the Developer's Handbook (Litwin, Getz, and Gunderloy).

I agree with Missingling that autonumbers are best left out of sight from the users.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top