Results 1 to 12 of 12
  1. #1
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85

    Compact & Repair and Autonumber issue


    Hello all,
    I have a database that is used to track orders. As part of the system I use autonumber fields to create unique order numbers and receipt numbers. I getting some "not responding" messages in the database and would like to run a Compact and Repair to clean it up. The problem is that when I run the compact and repair I know it will reset the autonumber fields to 0 and I will end up with duplicate order and receipt numbers in my table. In the past I have manually fixed this kind of problem by creating a dummy table with the appropriate number of records which I can append (and then delete) to the autonumber source table which will reset it to the current number. Is there a simpler way to do this, to tell the autonumber system that I want the next number to be a specific number after it has been reset in a compact and repair event?

    Thanks for the help.

    Roncc

  2. #2
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Quote Originally Posted by Roncc View Post
    The problem is that when I run the compact and repair I know it will reset the autonumber fields to 0 and I will end up with duplicate order and receipt numbers in my table.
    This is not the case. While it will reset the counter it won't change the values in your records or cause duplicates.

    Make a backup copy of the DB and give it a try.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    The only time that compact and repair will reset autonumbers to 0 is when you delete all records in that table/tables.. The table(s) must have all records deleted for it/them to have its autonumbers set to 0. After the C/R, the autonumber will start at 1.

  4. #4
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85
    I must not have made myself clear on the issue, I apologize. The way the program works is as follows: I have a table called NewNumberTbl that has a field called Id which is an autonumber field and a text field called NewRecord. I also have a table called NewNumberTemplateTbl which is a single field called NewRecord. I have a third table called OrderTbl containing all the fields needed for ordering, including a number field called OrderNumber. When I want to place a new order I append the single record in the table NewNumberTemplateTbl to the table NewNumberTbl which sets the autonumber in the Id field to the next number. I then append the single record in the table NewNumberTbl to the table OrderTbl where the Id number is placed in the field OrderNumber so now I have a new order record with a unique order number. After I am finished with my data entry for the new order, I close the table and use a delete query to remove the single record in the table NewNumberTbl. When I run a Compact and Repair I am not worried about the numbers being reset in the table OrderTbl, I know they will not be affected however, the autonumber in the table NewNumberTbl will be reset so when I create a new order the numbering system will start over and I will get duplication in the OrderTbl.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Your problem is your mis-use of the auto number feature. I'm on my phone so I can't grab the links I use to point people to what auto numbers are and are not. I'm surprised that no one has taken that view yet. Suggest you research them or perhaps others will provide the usual go-to links. Not only that they are not to be used as meaningful data but neither should they be used to arrive at meaningful data.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,412
    The usual approach when the next order number is needed is to lookup the max existing order number in OrderTbl and add one to it.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    As long as the generated number is not part of a composite field or index, that simple approach can work, otherwise the other part(s) of the index are also required. In a shared db the timing of the number generation becomes important.
    Last edited by Micron; 07-07-2018 at 02:59 PM. Reason: added info

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    It is often helpful to include/attach a jpg of your tables and relationships.
    Here is a link to a free, generic Customer, Order and Invoicing data model.

    I don't understand the need for
    NewNumberTemplateTbl which is a single field called NewRecord
    but would be interested in knowing how you use this.
    With Access most use autonumber PK in each table. As has been mentioned you can use a field (datatype number), then use Dmax(that field value) + 1 for the next record in that table.

    Here is the link to the Autonumber info that Micron mentioned.


    Good luck.

  9. #9
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85
    I didn’t bother to explain the whole order program because I didn’t want waste people’s time. I simply wanted to see if anyone knew of a programmatic way to correct the reset of the autonumber system after a Compact and Repair event. To go into a bit more detail: the reason I use a multiple step system is that I may have several items (records in the table OrderTbl) that I want to have the same order number. For example; I may want to order paper, pencils, and pens from Staples. When I do this I create 3 new records in the table OrderTbl, one record for each item. I create a unique order number for these new records by appending the single record in the table NewNumberTemplateTbl to the (empty) table NewNumberTbl which creates a unique number in it’s (the single record in the table NewNumberTbl) Id field. I then use an update query to place that Id number in the OrderNumber field for each of the new records. The new records in the table OrderTbl have alogic field which defaults to True when the record is created, the new OrderNumber only populates those records in the table OrderTbl if this logic field is true,and once the OrderNumber has been populated I run an update query which sets all these logic fields in the table OrderTbl to false. When I am done I delete the single record in the table NewNumberTbl and I am ready to use it for the next order number.

  10. #10
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85
    I don't think I'm misusing the autonumber feature as I am using it to create a unique number for each iteration. I don't care if they are sequential, I only care that they are unique. I posted some additional details in another response. Thank you for taking the time to assist though, I really appreciate it.

  11. #11
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85
    I figured out how to use the Dmax function suggested by davegri and Orange. I think I'll redesign things to work with that.
    Thanks for all the suggestions and the time you all spent working on my issue. I really, really appreciate it.

    Roncc

  12. #12
    Join Date
    Apr 2017
    Posts
    1,679
    Quote Originally Posted by Roncc View Post
    To go into a bit more detail: the reason I use a multiple step system is that I may have several items (records in the table OrderTbl) that I want to have the same order number. For example; I may want to order paper, pencils, and pens from Staples. When I do this I create 3 new records in the table OrderTbl, one record for each item. I create a unique order number for these new records by appending the single record in the table NewNumberTemplateTbl to the (empty) table NewNumberTbl which creates a unique number in it’s (the single record in the table NewNumberTbl) Id field. I then use an update query to place that Id number in the OrderNumber field for each of the new records. The new records in the table OrderTbl have alogic field which defaults to True when the record is created, the new OrderNumber only populates those records in the table OrderTbl if this logic field is true,and once the OrderNumber has been populated I run an update query which sets all these logic fields in the table OrderTbl to false. When I am done I delete the single record in the table NewNumberTbl and I am ready to use it for the next order number.
    This approach is faulty!

    You need a table tblOrders with autonumeric OrderID, with fields unique for order, like OrderDate, OrderNumber, ClientID, etc.
    And you need a table tblOrderDetails with autonumeric OrderDetailID, and Long Integer foreign key OrderID, where the value of OrderID from tblOrders is stored to link every order row to order. In this table you'll have fields unique for particular order row, like ItemID, Quantity, Price, etc.
    For every order, there'll be only one row of data in tblOrders. For every row in tblOrders , there'll be one or several rows with same OrderID in tblOrderDetails.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Compact and Repair
    By cwitt11 in forum Access
    Replies: 4
    Last Post: 12-08-2015, 11:52 AM
  2. Replies: 1
    Last Post: 09-02-2014, 09:41 AM
  3. Compact and repair
    By data808 in forum Access
    Replies: 4
    Last Post: 03-30-2014, 03:22 AM
  4. Compact and Repair
    By Cyberice in forum Access
    Replies: 3
    Last Post: 03-18-2014, 03:22 PM
  5. Technical Issue with Compact & Repair
    By prstoessel in forum Access
    Replies: 8
    Last Post: 01-23-2014, 03:22 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums