Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Aug 2001
    Cape Town, South Africa, South Africa
    Thanked 0 Times in 0 Posts

    Value 1-1000 (Access2000)

    If I have a table (NoID, SeqFrom and SeqTo). I would like to populate the SeqFrom and SeqTo as follows:

    NoID, SeqFrom and SeqTo
    1 1 50
    2 51 100
    3 101 150


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Value 1-1000 (Access2000)

    I assume that you have created the table, but it is still empty.
    Create a VBA module.
    Set a reference to Microsoft DAO ... Object Library (in Tools/References...)
    Copy the following code into the module:

    Sub FillTable()
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Dim lngIndex As Long

    On Error GoTo Err_Sub

    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("tblName") ' Substitute actual table name
    For lngIndex = 1 To 1000
    With rst
    !NoID = lngIndex ' Omit this instruction if NoID is an AutoNumber field
    !SeqFrom = (lngIndex - 1) * 50 + 1
    !SeqTo = lngIndex * 50
    End With
    Next lngIndex

    On Error Resume Next
    Set rst = Nothing
    Set dbs = Nothing
    Exit Sub

    MsgBox Err.Description, vbExclamation
    Resume Exit_Sub
    End Sub

    Replace tblName by the actual name of your table.
    If NoID is an AutoNumber field, remove the line setting NoID, or make it into a comment.
    Place the insertion point somewhere in the procedure and type F5 or click the Run button.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts