Function for Numbering Table

  • Thread starter Marcelo Henderson via AccessMonster.com
  • Start date
M

Marcelo Henderson via AccessMonster.com

How can I make a function that fill automatically a table with numbers :
1 to 500

Regards,
Henderson
 
F

fredg

How can I make a function that fill automatically a table with numbers :
1 to 500

Regards,
Henderson

Assuming you already have a table name "tblOfNumbers" with a field
named "ANumber", Number datatype, Field Size LongInteger (or Integer).

Change the table and Field names as needed.

Public Sub FillATable()
' Will fill a table field with incremented numbers
Dim Db As Database
Dim rs As Recordset
Dim lgCounter As Long
Dim intStart As Integer
Dim intEnd As Integer
Set Db = CurrentDb

Set rs = Db.OpenRecordset("tblOfNumbers", dbOpenDynaset)
intStart = InputBox("From?", "Start with #", 1)
intEnd = InputBox("To?", "End with #", 500)

On Error Resume Next
For lgCounter = intStart To intEnd
With rs
.AddNew
![ANumber] = lgCounter
.Update
End With
Next lgCounter
rs.Close
Set rs = Nothing
Set Db = Nothing

End Sub
 
C

chun

I just did this today. If you only have 500, there is a simple way to do it.
Just open the table, put 1 at the frist record and 2 at the second record,
then immediately (before doing anything else) push the downward arrow key and
Access will fill the number for you. It is kind of like a spread sheet where
you fill a couple of numbers and then drag down to populate the reset of the
cells. It just take a few seconds.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top