auto populating number field with large amounts of numbers.

  • Thread starter Thread starter Frank
  • Start date Start date
F

Frank

I have a table with one number field in it. I want to populate that field
with numbers 1 through 200,000 automatically - ie. all at once. How do I do
this?

Your assistance is greatly appreciated.
 
1. Paste the following into a standard module.

2. Replace "MyTable" with the name of your table, and "MyID" with the name
of your number field.

3. Check that it compiles: Compile on Debug menu.

4. Open the Immediate Window (Ctrl+G), and enter:
? MakeData()

Function MakeData()
Dim rs As DAO.Recordset
Dim lng As Long

Set rs = DBEngine(0)(0).OpenRecordset("MyTable")
For lng = 1 To 200000
rs.AddNew
rs![MyID] = lng
rs.Update
Next
rs.Close
MakeData = "Done!"
Set rs = Nothing
End Function
 
Allen:
Thanks for comments. Will try and post the results.


Allen Browne said:
1. Paste the following into a standard module.

2. Replace "MyTable" with the name of your table, and "MyID" with the name
of your number field.

3. Check that it compiles: Compile on Debug menu.

4. Open the Immediate Window (Ctrl+G), and enter:
? MakeData()

Function MakeData()
Dim rs As DAO.Recordset
Dim lng As Long

Set rs = DBEngine(0)(0).OpenRecordset("MyTable")
For lng = 1 To 200000
rs.AddNew
rs![MyID] = lng
rs.Update
Next
rs.Close
MakeData = "Done!"
Set rs = Nothing
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Frank said:
I have a table with one number field in it. I want to populate that field
with numbers 1 through 200,000 automatically - ie. all at once. How do I
do
this?
 
Back
Top