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?
 

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

Similar Threads

Auto Populate Field 2
Auto Populate Column 4
Auto Populate a Field 1
simple formatting 18
Auto Number Lookup 1
Incremental Numbering 5
Autopopulated field in form 2
MS Access problem 0

Back
Top