Results 1 to 4 of 4
  1. #1
    jlgray0127 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2011
    Location
    Central Illinois
    Posts
    185

    Code for Adding Sequence to set of records is dynamic and not sequential

    I have a make table query which I am using to compare two data sets from two different sources. These are Builds of Material and have to be in sequential order to do the data comparison. A1A has to be on line 1, A1B has to be on line 2. If it is not, that is an error in the comparison.

    I require the ability to assign a sequential number to each record from both sets of data when I pull the data sets into Access to not lose the order the data is stored.
    I have a make table query for both sets of data to create a temp table.

    I've used the VBA code:

    Global seqNumber As LongGlobal lastcall As Date


    Function wAutoNumber(i) As Long
    If Now - lastcall > 4 / 60 / 60 / 24 Then
    lastcall = Now
    seqNumber = 0
    End If
    seqNumber = seqNumber + 1


    wAutoNumber = seqNumber
    End Function

    What I found, is does not stay sequential (1,2,3,4...) its coming out 1,235, 68, 69, 70, 3, 6, 4, etc....

    I can not compare the two records this way. Am I missing something in my code? This is the first time I've used this one, and not seeing why it would not be sequential.

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Sample data would help, along with knowing what values are being passed to your function. If Now-lastcall is greater than the expression, your counter starts over again. I guess that's what you want? Also, using Now might be an issue - depends on what your date values really are, not just what they look like due to formatting in the table or query. As functions, Now will always be greater than Date.
    Last edited by Micron; 02-11-2022 at 10:43 AM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    why not just use a query joining the two tables on the common value?

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

Similar Threads

  1. Adding a numerical sequence value to a field
    By Mattbro in forum Queries
    Replies: 6
    Last Post: 03-30-2019, 10:10 AM
  2. Replies: 8
    Last Post: 08-21-2017, 11:13 AM
  3. Replies: 3
    Last Post: 12-22-2016, 12:54 PM
  4. Adding numbers in sequence
    By howlettb in forum Access
    Replies: 6
    Last Post: 12-31-2013, 02:30 PM
  5. VBA code for adding records to a table
    By pwalter83 in forum Forms
    Replies: 3
    Last Post: 12-21-2011, 10:52 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