Results 1 to 7 of 7
  1. #1
    Lesg is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    101

    unique sequential invoice numbering


    Hi Guys,

    Looking for suggestions to avoid duplicate invoice numbering we are experiencing as system has been introduced to multiple users.

    The orders table has an orderID which is the autonumber for the table, however, as the client wants to ensure they have sequential numbering for invoices a field 'invoice' was created and as part of the open form process a new invoice number is created using the following code:

    Code:
    Forms!frmOrderPlacement!invoice = Nz(DMax("[invoice]", "orders"), 0) + 1
    The problem with this is, if another user starts an invoice before the current one is save, the same number can be added to the next invoice, hence there is then duplicated invoice number.

    This only happens quite rarely, but often enough to be a nuisance, so if anyone can suggest a better way to handle this I would appreciate it?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    Safest way is to only get next number as you commit the record, not as you dirty the record.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Another option is to store the last invoice number in a table, and always update it as soon as an new number is issued.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    Quote Originally Posted by Minty View Post
    Another option is to store the last invoice number in a table, and always update it as soon as an new number is issued.
    Doesn't that leaves gaps if the user backs out of finishing the record?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Quote Originally Posted by Welshgasman View Post
    Doesn't that leaves gaps if the user backs out of finishing the record?
    I would normally record that invoice as Cancelled, and leave a record of it.
    The other method is to check if it's not been updated when you cancel the record and reset it back where to the original number.

    TBH all methods are not 100% fool proof, which is why marking something as cancelled/deleted is actually by far the safest route.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    The most foolproof method I found: create a sequence for the invoice numbers. In Access this can be a table with one (or more if you have different numbering for credit notes) number field. You create your invoice in status 'created'. As long it is inthis status you can still alter the invoice. Once you click the button 'print' an invoice number is fetched from the sequence table and the number in the sequence table is augmented with 1. Once your invoice is numbered you cannot change the invoice any more.
    Fetching the number from the sequence table is very fast and there is little chance 2 users will be doing this at the same time, and if so, the second user will be blocked by the update.

  7. #7
    Lesg is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    101
    Thanks for those suggestions guys, all of which I have considered, and valid, so will test out all to see which works the best, thank you

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

Similar Threads

  1. Sequential numbering in a table
    By PCData in forum Programming
    Replies: 3
    Last Post: 02-07-2020, 05:44 AM
  2. Sequential numbering help
    By mtmtfranz in forum Macros
    Replies: 1
    Last Post: 09-30-2019, 08:45 AM
  3. Sequential Numbering
    By thegrimmerdiscovery in forum Access
    Replies: 3
    Last Post: 07-16-2019, 06:15 AM
  4. Confusing Invoice Sequential Numbering with Year and "BW"
    By breakingme10 in forum Programming
    Replies: 8
    Last Post: 07-22-2014, 09:11 AM
  5. Help with Sequential Numbering
    By orion in forum Programming
    Replies: 3
    Last Post: 07-06-2009, 01:41 PM

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