Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2024
    Posts
    1

    Number list


    How do I create a simple column of sequential numbers?

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Without more context, here is some code to build a 1 column table and populate it with sequential numbers.
    You must supply a value for the nums parameter.

    eg. BuildNumbersTable (500) will build and populate 1 thru 500

    Code:
    Function BuildNumbersTable(nums As Long) As Long
    
        'Create and fill a numbers table - 10000 is a good start
        Dim rs As DAO.Recordset
        Dim X As Long
        DoCmd.RunSQL "CREATE TABLE tblNumbers([Num] long PRIMARY KEY)"
        Set rs = CurrentDb.OpenRecordset("tblNumbers")
        For X = 1 To nums
            rs.AddNew
            rs(0) = X
            rs.Update
        Next
        rs.Close
        MsgBox "Table Built"
    End Function

  3. #3
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi Keith
    Can we ask why you need a column of numbers?
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  4. #4
    madpiet is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    154
    Quote Originally Posted by mike60smart View Post
    Hi Keith
    Can we ask why you need a column of numbers?
    So he can do cool things without stupid VBA loops?

  5. #5
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Autonumber datatype?

  6. #6
    madpiet is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    154
    Works okay unless something odd happens and one of the inserts does something stupid. Then the number gets skipped.

  7. #7
    Join Date
    Apr 2017
    Posts
    1,680
    Or...
    Create an single-column Excel table, enter a couple of starting numbers, and copy down;
    Link the Excel table into Access DB
    In case those numbers are used repeatedly in Acceess DB, use INSERT INTO query to fill your Access table with numbers from linked Excel table, and after that remove the linked table - otherwise just do what you wanted, and then remove the link.

    Another way:
    Create an Access table (e.g. tblNumberList) for numbers (e.g. with field Num), and enter manually numbers e.g. 0 - 9;
    Create an INSERT QUERY like;
    INSERT INTO tblNumberList SELECT (1*10)+Num from NumberList;
    Run the query for multipliers from 1 to 9;
    Repeat the previous cycle with 1*100 instead of 1*10;
    Repeat the previous cycle with 1*1000 instead of 1*100;
    etc.

    I think it takes not much time until you reach the limit for number size.
    And in case this is too much of manual work, create a multi-cycle procedure, which runs the same query instead.

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    I use a numbers list similar to avril’s but I just use the query rather than changing it into an append query.

    edit: now back online so this is what I do

    1. create a table with a single field and populate with the values 0 to 9 (my table is called usysCounter and the field, num)
    2. use this query (I called it qryCounter) to generate numbers from 0 to 9999
    Code:
    SELECT CLng([singles].[num]+([tens].[num]*10)+([hundreds].[num]*100)+([thousands].[num]*1000)) AS [Counter]
    FROM usysCounter AS singles, usysCounter AS tens, usysCounter AS hundreds, usysCounter AS thousands;
    you can add more if you need over 9999
    3. use another query to restrict the range or create dates e,g, this one creates a range of 100 days from today
    Code:
    SELECT date()+counter as dateRange
    FROM qryCounter
    WHERE counter <100
    Last edited by CJ_London; 01-06-2024 at 04:25 AM.

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

Similar Threads

  1. Customizing list number format
    By BudMan in forum Access
    Replies: 2
    Last Post: 03-06-2022, 10:47 AM
  2. Replies: 8
    Last Post: 12-13-2017, 10:38 AM
  3. List Box number sort
    By JimO in forum Access
    Replies: 3
    Last Post: 12-10-2017, 02:22 PM
  4. Number Format for a List in a Report
    By Huddle in forum Reports
    Replies: 1
    Last Post: 05-12-2012, 10:29 AM
  5. Associate Number with Each List Box Choice
    By beribimba in forum Access
    Replies: 8
    Last Post: 08-25-2011, 08:31 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