Problem with automatic number in a table (1 Viewer)

Matin_Murad

Member
Local time
Today, 12:00
Joined
Jul 1, 2020
Messages
37
If the table is empty and there is any problem in the attachment
Access takes a backup and the automatic number starts from a new number that is 1 (I do not want an automatic number to be returned again)
And an automatic number starts again when performing a data command lineup and fixing it
 

Attachments

  • fatoraa.accdb
    396 KB · Views: 100

theDBguy

I’m here to help
Staff member
Local time
Today, 12:00
Joined
Oct 29, 2018
Messages
21,454
Hi. If you want a controllable automatic number, you'll have to create/use your own. Otherwise, the built-in Autonumber will just keep doing what it's supposed to do. Just a thought...
 

Matin_Murad

Member
Local time
Today, 12:00
Joined
Jul 1, 2020
Messages
37
thank you teacher
Any number suitable for the invoice in the table and provided a number does not return to the beginning when problems (In the table only)
The automatic number returns the start on problems, and a backup copy if the table is empty
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:00
Joined
Oct 29, 2018
Messages
21,454
thank you teacher
Any number suitable for the invoice in the table and provided a number does not return to the beginning when problems (In the table only)
The automatic number returns the start on problems, and a backup copy if the table is empty
Hi. If you do a search on "autonumbers" or "sequential numbers" or "auto incrementing numbers," you should see some samples/demoes on how to create your own Autonumber field. Maybe you could try that. Good luck!
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:00
Joined
Feb 28, 2001
Messages
27,146
@Matin_Murad - the correct behavior of autonumbers is that if the table is empty at the time and a Compact & Repair is performed, it resets the autonumber to 1. This is the published behavior of autonumbers so when it happens it is not an error. But this only happens when the table is empty. Which leads me to the question, "Where did you expect the number to be retained so that it can be updated?" If the table is empty, the lowest available number IS 1 and that's what you got.

I looked into the file you posted. It looks normal to me. It behaves normally when I create a new record. The file you posted doesn't contain enough other stuff to HAVE problems so there is nothing for us to test.
 

Matin_Murad

Member
Local time
Today, 12:00
Joined
Jul 1, 2020
Messages
37
The idea has arrived, thank you: it is necessary to not delete the data from the table permanently because it returns the automatic number when pressing and repairing, and when problems occur, if the table is empty, the automatic number returns to the number 1
The automatic number includes a sequence when reaching the number 100, deleting the table data, and when entering data again, the number must reach 101
If the table is empty, the automatic number reaches the number 1
When problems arrive, Access takes a backup copy of the attachment and arrives at an empty automatic number 1
Roughly this is a problem with Access data
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:00
Joined
Feb 28, 2001
Messages
27,146
OK, here is a thought. It is a Compact & Repair that will reset autonumbers. Even if you do a DELETE * FROM table-with-autonumber ; the next number in sequence should be retained as it is a property of the TableDef structure for that table. Erasing a table doesn't reset the autonumber. Running the C&R resets the autonumber. There is also a manual way to do that but it isn't recommended. Therefore, if your problem is the reset of that number, just remember that anything forcing a Compact & Repair will do that reset on an empty table. So don't empty it right away.

You say "When problems occur" but I think where you have the REAL problem is your response to the first problem. So as you say, it is necessary to NOT delete the data after an error. Examine some other error response.

Also, be aware that if you are using autonumbers to generate a number that has some meaning, this is actually NOT a recommended usage. Autonumbers are simply numbers guaranteed to be unique and their direction of change is predictable. But their specific value is not. It is very easy for an autonumber to present you with a gap in numbers if there was an error such that a particular record didn't get stored. If you have an audit process that involves contiguous numbering, autonumbers are not well-suited for that. I mention that because some of our users have tried to use autonumbers but then find out that either a corporate or a government regulation makes autonumbers unsuitable in that usage.
 

Users who are viewing this thread

Top Bottom