Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add block of numbered records 1

Status
Not open for further replies.

LynneAOG

MIS
Jun 23, 2004
4
US
I need a query or VBA code that will add a block of numbered records that add the number of records a user designates and increments the records by one from the last record in use. For example, if there are 100 records and the user wants a block of ten, I need to add records with the numbers 101 through 110. Thanks -
 
The easiest way for the numbering process is to set the ID field as an Autonumber. This will then number the records automatically starting with the next number. Let's proceed as if you are going to do this. The following VBA code will add the numbered of records that the user indicates. Now this is also dependent upon not having any fields that are required as we don't know what values they will have at this time. We are just adding blank records.

Code:
Dim db as DAO.Database
Dim rs as DAO.Recordset, i as Integer, vRecords as Integer 
Set db = CurrentDB
Set rs = db.OpenRecordset("[i][red]yourtablename[/red][/i]", dbOpenDynaset)
vRecords = InputBox("How many records to add to table?)
For i = 1 To vRecords
   rs.AddNew
   rs.Update
Next i
rs.close
db.close

This will create the number of records that the user enters after being prompted. If you don't want to modify the table to use the AutoNumber then post back and we can add that code here also. Tell me at that time what the name of the table is and the name of the record number field is.








[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top