How to reset Access 2007 autonumber at certain row - ms-access

I have an Access 2007 database schema where the central table has a primary key which is an auto number. I have to delete records I input in the foreign table to re-input them and so want to delete the parent reference from the central table. What I want to know is how can I set the cebtral table autonumber to start counting again from before I input the records the first time? That is before I input the records the autonumber was at 2380 but now is at 2523, if I delete all after 2380 how do I get the auto number to restart again at 2381 when I insert the records again

After you delete the rows from the specified table you need to do a "Compact and Repair Database" operation on the database file. That will have the effect of resetting the next AutoNumber value to (the_current_largest_AutoNumber_value + 1).
For details on how to do a "Compact and Repair Database" in Access 2007, see the "Manually compact and repair a database" topic in the following Microsoft Support article:
Help prevent and correct database file problems by using Compact and Repair

Related

MS Access: How to automatically populate a PK that is also a FK to another tables auto increment PK?

I'm working on updating a MS Access application that is connected to a MySQL database through an ODBC connector. I'm currently stuck on an issue where I have a form thats record source is a query that joins multiple tables, the 2 tables of issue are roughly structured as shown below.
Table1 {
id int not null auto increment,
...,
primary key(id)
}
Table2 {
table1ID int not null default 0,
...,
primary key(table1ID),
constraint `fk` foreign key (table1ID) references Table1 (id) on delete cascade on update cascade
}
The problem being that Table2's primary key is also a foreign key that references Table1's id and because they are joined in the same query for the record source they both get created at the same time. So when I attempted to add a new record in MS Access, it won't save the record because Table2's "table1ID" is null but Table1's "id" is auto increment so isn't created until the record is first saved. So my question is... is there a way to have MS Access/MySQL automatically fill in Table2's "table1ID" with the auto increment value from Table1's "id" so that MS access is able to save the record?
The error message that gets returned upon trying to save a new record is as follows:
Run-time error '3155':
ODBC--insert on a linked table 'Table2' failed.
[MySQL][ODBC 8.0(a)Driver][mysqld-8.0.27]Column 'table1ID' cannot be null (#1048)
You have to execute a save in the form that creates the table 1 record.
In fact, this is also why Access will execute a automatic record save in a form when you move focus to the sub form. Access does this, since the autonumber ID on a new reocrd is NOT created until you save the reocrd (at least this is the case when using a ODBC data source). With access only, the reocrd save is not required to generate the PK id, but with sql server, or MySql - you MUST save the record.
As noted, with a form + sub form, access does this automatic.
However, say I am on a form, just added a new reocrd, and now i want to run some code, or launch another form? I MUST force a reocrd save first to generate the PK autonumber.
So, code will look like this:
if me.dirty then me.Dirty = false ' save reocrd
' now do your other business here, code that follows, or
' even launch another form, or whatever.
So, a simple force of form record save with me.Dirty = false will force the autonumber generation.
I don't know how MySQL works with a join between two tables, but as a general rule only ONE of the two tables in the join can be updated at a given time.
Thus, you have to break out the steps here, or not allow both tables to be edited (or at least dirty at the same time).
Access does and did allow both tables to become dirty, but server side systems to my knowledge do not. So, you could while editing on the form, when you tab out of a control that is based on the one record, you would execute a me.Dirty = false to generate the auto PK.
However, I don't recommend allowing editing of a form that is based on more then one table at a given time - most server systems don't allow this.
So, add, and save that first record before any child record is attempted to be added here.

Microsoft Access Reusing Record ID's

I have a (Microsoft access office 365 database). I have a number of records in a table in the database. Lets say I have 5 records numbered 1 to 5 respectfully. now when I delete record number 3. Record number 3 is now gone. The problem I am having is when I create a new record I see that record number 3 is being used again as a record number despite the fact that record number 3 has been deleted. This to me should not be happening. I recently upgraded the Microsoft Access Database Engine redistributable 2016 on our server from 2010. Thinking this might resolve the problem. The data type and primary key for the archiveID field is AutoNumber.
Please advise.
Some times AutoNumber can be damaged, for example by manual assignment. Try to repair it:
INSERT INTO [TableName]([archiveID]) SELECT MAX([archiveID]) FROM [TableName];
And check if problem repeats.

Microsoft Access linked table (ASE) with trigger error

I have in Microsoft Access a linked table to an ASE Server.
On the server side, the table has no primary key or identity columns.
And has a trigger on insert that validates new entries, so that when the entry is not validated it deletes the entry from the table and writes to "table"_ERR to let the users know what error was produced.
When linking it to Access a composite key is created using 10 columns.
I have this same setup in 10 different tables (all with triggers all linked to Access)
In this particular table when trying to insert/append records to the table through Access i always get the error message:
Single-row update/delete affected more than one row of a linked table. Unique index contains duplicate values.
This error occurs when both table and table_ERR are empty and i'm only trying to insert 1 record.
If I disable the trigger i have no problem inserting records through Access
I have similar triggers in other tables that are working correctly.
What can be causing this issue and does anyone know how to solve this?
I have read that MS Access can mess up the ##identity, even so none of the solutions presented online seem to work.
links : https://groups.google.com/forum/#!msg/microsoft.public.sqlserver.programming/McHdRpPKMhs/SlyObU8w7JMJ
Stop Access from using wrong identity when appending to linked table on SQL server
Thanks in advance.
EDIT: if i try to insert the records directly from a management software (like Aqua Data Studio) there are no erros
Without knowing more specifics about your data itself, it is difficult to say why this might be happening.
However, it sounds like in this specific instance for this specific linked table, your 10 columns are not unique enough to prevent non-distinct rows from being selected.
Suggested fixes:
Add a primary key. Honestly, probably the best and easiest choice.
If for some reason you cannot add a new column to (or alter) your table; you may be able to re-link your table, and re-choose your 10 columns so that they are more unique.
Beyond that, I think we would need more information.
Just out of curiousity, what is the reason for having no key?

Update all rows except identity column in Access 2013

I have a form in Access linking to a SQL Server table. This table has a UID. After I create a new record in Access, it tries to update the table (including the UID) and gives me the error:
Explicit value must be specified for identity column in table 'TableName' either when IDENTITY_INSERT is set to ON or when a replication user is inserting into a NOT FOR REPLICATION identity column.
Now, I understand why this error is occurring but am not sure how to get around it. I can't change IDENTITY_INSERT, and the UID column in Access links the form to a subform, so I do need to include it in the form. How do I exclude only the UID column from the ODBC update? I know I can use a macro to explicitly define columns to update, but there must be an easier way. Is there a function like Me!UIDTextbox.Undo I can run in the Before Update event?
Some more detail:
There's no VBA module or query in Access. It's a standard SQL server table and the Access form updates the table on record change (the default for Access). The table is linked with the standard ODBC Database connection, with the UID as primary key.
This may be a global problem with using Identity columns as Primary Keys in Access.
Patch idea and possible workarounds at
Problem with identity fields in MS-Access

MySQL backend & Access (.accdb, 2013) Frontend Auto Increment Issue

I have a MySQL database that the tables are each set up with an ID field which is an auto increment and primary key. When I use access to link to this database and tables in table design view in Access the fields are listed as the primary key but the type is number, not auto number. This is causing an issue when trying to create a new record because the ID field is not being populated automatically. Please help.
The autonumbering property of the id fields is set at the level of the MySQL database. Access might not be able to identify this property when connected to the back end database. This is why it considers it as a number, and not an autonumber, field.
This said, when inserting new records in the MySQL database, you do not need to send any value for the id field, so the MySQL engine automatically fills it with the updated autonumber value.