How to populate sequential numbers in a field using SQL or VBA?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Excel 009

    How to populate sequential numbers in a field using SQL or VBA?

    Hi,

    Is there a way to populate sequential numbers in a field using SQL or
    VBA? If yes, how?

    Assume the following is my existing table:

    Fruit ID
    Apply
    Banana
    ..
    ..
    Orange

    and I want to populate the ID field with 100, 101, 102.....

    (I do not want to use append query with autonumber field.)

    Excel 009

  • paii, Ron

    #2
    Re: How to populate sequential numbers in a field using SQL or VBA?


    "Excel 009" <excelmodeling@ gmail.comwrote in message
    news:87e4f2ef-3e8f-4842-aa06-174af4e5991d@w1 g2000prd.google groups.com...
    Hi,
    >
    Is there a way to populate sequential numbers in a field using SQL or
    VBA? If yes, how?
    >
    Assume the following is my existing table:
    >
    Fruit ID
    Apply
    Banana
    .
    .
    Orange
    >
    and I want to populate the ID field with 100, 101, 102.....
    >
    (I do not want to use append query with autonumber field.)
    >
    Excel 009
    >
    Create a Temp table with 2 fields
    1) AutoNumber
    2) Keyvalue

    Use a append query to fill the temp table's [KeyValue] with the primary key
    value of you data table.
    Run an update query using the AutoNumber to fill the ID field
    ([AutoNumber]-1) + 100.


    Comment

    • Karl

      #3
      Re: How to populate sequential numbers in a field using SQL or VBA?

      x = 100

      Do While Not rst.EOF

      rst.edit
      rst![ID] = x
      rst.update

      x = x +1
      rst.movenext
      Loop

      "Excel 009" <excelmodeling@ gmail.comwrote in message
      news:87e4f2ef-3e8f-4842-aa06-174af4e5991d@w1 g2000prd.google groups.com...
      Hi,
      >
      Is there a way to populate sequential numbers in a field using SQL or
      VBA? If yes, how?
      >
      Assume the following is my existing table:
      >
      Fruit ID
      Apply
      Banana
      .
      .
      Orange
      >
      and I want to populate the ID field with 100, 101, 102.....
      >
      (I do not want to use append query with autonumber field.)
      >
      Excel 009
      >

      Comment

      • Excel 009

        #4
        Re: How to populate sequential numbers in a field using SQL or VBA?

        Thanks guys! I will experiment with each of the methods you guys
        provide and let you know.

        Anyone has a new idea, please feel free to provide. Thanks.

        Excel 009

        Comment

        Working...