Results 1 to 6 of 6
  1. #1
    Raveen1609 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Posts
    53

    Access Multiple user Auto Number jumping

    I have a receipt generating access application. I have used auto number for my receipts, but the number jumping. So I created a SequentialID number field and used following code to enter before insert event. But since I am not able to index the same with no duplicates, the users got duplicate receipt numbers. How do I solve this issue.
    Private Sub Form_BeforeInsert(Cancel As Integer)
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim newID As Long

    Set db = CurrentDb
    Set rs = db.OpenRecordset("SELECT MAX(SequentialID) AS MaxID FROM [Seva Details Query];")

    If Not (rs.EOF And rs.BOF) Then


    newID = rs("MaxID") + 1
    Else
    newID = 1
    End If

    Me.SequentialID = newID

    rs.Close
    Set rs = Nothing
    Set db = Nothing
    End Sub

  2. #2
    Join Date
    Apr 2017
    Posts
    1,679
    Why you can't index it?

    You can have only one primary key (a single or multiple field one), but you can additionally have any number of unique indexes (NB! Primary Key and Indexes are not the same!).

    Keep the autonumber ID in your table as Primary Key. Add another field (e.g. SequentialNo), and set this field indexed uniguely. The insert query must be something like
    INSERT Into YourTable (SequentialNo, Field1, Field2, ...)
    SELECT Expr1 AS SequentialNo, Field1, Field2, ...
    FROM TourSourceTable ...

    NB! As you see, the query doesn't contain the autonumeric ID (you can't force autonumeric values)!

  3. #3
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Does it matter if the receipt numbers are not sequential? It is still unique. Also is this a single application on one PC or is it say on multiple PCs with data on network so producing receipts from different locations?

  4. #4
    Raveen1609 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Posts
    53
    Thanks for your response. Yes it matters the receipt number should be sequential to avoid misuse. Same single application, with split backend tables, used in 2 PCs in different locations

  5. #5
    Raveen1609 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Dec 2019
    Posts
    53
    For unknown reason, when I save the table after creating a sequnetialID field, and index and set to no duplicates, it is not accepted.

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    and set to no duplicates, it is not accepted.
    probably because you already have duplicates

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

Similar Threads

  1. Replies: 3
    Last Post: 01-13-2020, 07:24 AM
  2. Replies: 5
    Last Post: 11-30-2014, 12:46 PM
  3. Replies: 1
    Last Post: 10-25-2013, 03:38 PM
  4. Access 2007 Auto Number?
    By katie365 in forum Forms
    Replies: 4
    Last Post: 05-02-2012, 07:59 AM
  5. Access Auto Number Help
    By jsmmao in forum Access
    Replies: 12
    Last Post: 01-12-2010, 11:17 AM

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