Results 1 to 4 of 4
  1. #1
    niktsol1978 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    12

    Assign a custom auto increment number

    Hello everyone. Here is the scenario of my project:

    Each office, where i work, has its own incoming documents, in which a unique number per year, should be assigned , once document info is entered in the database. This unique number will be increased by one for the new incoming document and every new year's eve is reset back to 1. Each office has its unique "autonumbering". The database i am creating will be in multi-user environment. So i thought 3 ways to assign a unique reference number per office.

    1) Using DMax function, in which i will search for the maximum reference number at that time in the document's table, +1. But, i've searched that Dmax, might have some issues in multiuser environment (assign two same numbers if users work simultaneously the same process)
    2) Making a index with office ID , reference number, and current year (non duplicates) so by using Dmax, if the above problem occurs i will trap the error and loop again the assign new reference number procedure. But, what happens, when multiple users run the same process? Is it possible a deadlock or something?


    3) Create a counter table with fields such as <OfficeID>,<ReferenceNumber>,<CurrentYear>. When a new document is entered as incoming document in <OfficeID>, then with a DAO Recordset i could retrieve the <ReferenceNumber> value, at the <CurrentYear>, with a Recordset Pessimistic lock, in case another user does the same process. If an error occurs, then there will be a loop in the whole procedure. I also believe that using this implementation, each new year's eve, i will reset to all <OfficeID> fields the <ReferenceNumber> to 1 and also the <CurrentYear> to new year.

    I believe the solution number 3 is more reliable at all. I am glad to read your opinions, as well. Please feel free to suggest any other possible solution(s).

    Thank you in advance.
    Last edited by niktsol1978; 04-25-2020 at 11:54 PM.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    OfficeID, DocID (autoNum) is all you need for unique.
    Ref#, and EntryDate for your use.
    entrydate will give you year thus no need to do any 'calculation'.
    Having a counter reset to 1 every year is not needed. The timestamp does this for you with no vb needed.

  3. #3
    niktsol1978 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    12
    The DocID is not autonumber field. I don't know the document ids that i will receive from other services, and the format of this Docid varies.

    How should i manage with timestap to reset the counter? You mean something like validation rule or something?

    Thank you in advance

  4. #4
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    Did you find a solution? I'm not sure I understand your reference id. Is it the incrementing number or a number already assigned to a document?
    The time honored simple solution in the past was id = office:date:milliseconds and test for clash. The foreign document id is just another field in the table. I'm not sure Access can do this schema with queries that can create a new record.

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

Similar Threads

  1. Replies: 10
    Last Post: 04-01-2018, 07:45 AM
  2. Replies: 1
    Last Post: 10-16-2013, 09:41 AM
  3. Auto increment on existing number column
    By lcsgeek in forum Programming
    Replies: 1
    Last Post: 04-15-2013, 11:27 AM
  4. Replies: 5
    Last Post: 11-12-2010, 12:10 PM
  5. Replies: 1
    Last Post: 06-25-2010, 07:15 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