Results 1 to 5 of 5
  1. #1
    losstww is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    5

    Find First number in sequence of numbers

    Access 2010, Windows 7



    I have a table with a column named CheckNumbers. I need to find the first number in a sequence of numbers. Example:

    123456
    123457
    123459
    123462
    157936
    157937
    157938

    The database has thousands of records.

    Any help would be appreciated!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    This is difficult even if the 'sequence' didn't allow gaps as shown in the sample data. Numbers are skipped between 123459 and 123462 yet 123462 does not begin a new 'sequence'. Which digit determines beginning of new 'sequence'? By this example appears to be second position. Consistency in criteria is key to accomplishing this.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    losstww is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    5
    The database is a list of fraudulent checks. Any consistency in check numbers implies that a particular person or group is generating the fraudulent checks. The first Check number in a sequence of numbers will be bumped up against a legitimate check number to determine if the originator was/is a possible employee. It has worked well manually but an automated process would save time. I am currently working on a function. I will post when I figure it out.

    Thanks for the response.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    What is the logic applied in the manual process? Can you represent it in a flow diagram?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    losstww is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    5
    I found a work around to get the first number in a sequence of numbers.

    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strDupNum As Variant
    Dim strSaveNum As Variant
    Dim tempvar As Variant
    Dim ct As Integer
    Set db = CurrentDb

    'Delete Temp Table if it already exists
    DeleteTable ("tbl_SequenceNumbers")

    'Create temp table to store sequence check numbers
    db.Execute "CREATE TABLE tbl_SequenceNumbers(check_num INTEGER)"

    'Open recordset sorting by check number
    Set rs = db.OpenRecordset("Select t.[CheckNumber] FROM [Tbl_BadChecks] As t WHERE t.[CheckDate] Between #7/1/2012# AND #11/1/2012# ORDER BY t.[CheckNumber] ASC")

    'get the record count
    ct = DCount("[CheckNumber]", "[Tbl_BadChecks]")

    'reiterate through the recordset pulling the first number in a sequence of numbers

    rs.MoveFirst
    Do Until rs.EOF
    strSaveNum = rs![CheckNumber]
    If tempvar = 0 Then
    tempvar = rs![CheckNumber]
    End If

    If rs.AbsolutePosition = ct - 1 Then
    db.Execute "INSERT INTO tbl_SequenceNumbers(check_num) VALUES (" & tempvar & ")"
    tempvar = 0
    Else

    If (tempvar + 100) > strSaveNum Then

    Else
    db.Execute "INSERT INTO tbl_SequenceNumbers(check_num) VALUES (" & tempvar & ")"
    tempvar = strSaveNum
    End If
    End If

    rs.MoveNext
    Loop

    I made an assumption that if a sequence of numbers is separated by a count of 100 then a new sequence should begin.

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

Similar Threads

  1. Enter new number in sequence in PO
    By tchirpich in forum Access
    Replies: 30
    Last Post: 12-30-2011, 11:24 AM
  2. Replies: 2
    Last Post: 06-11-2011, 10:39 PM
  3. Reverse Sequence of Numbers
    By OpsO in forum Queries
    Replies: 1
    Last Post: 08-12-2010, 06:05 PM
  4. Find Missing Number in Sequence per Record
    By escuro19 in forum Programming
    Replies: 1
    Last Post: 11-10-2009, 03:15 PM
  5. Auto Sequence String Serial Number
    By eddyc99 in forum Programming
    Replies: 2
    Last Post: 10-02-2009, 08:11 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