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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Table Entries from Form

Status
Not open for further replies.

starflt1701

Technical User
Jun 4, 2001
25
US
I want to use a form to update a table with autonumber. How do I modify a form to create multiple entries into the table, which will have identical information, except for the autonumber, without having to enter the same information into the form repeatedly. In other words, I want to enter the information into the form once, then enter a number variable into a box, and have the form populate the table with that many records. If this requires some code, as I suspect it might, please describe the code and where it will be entered.

Thanks.
 
It does require code. I'd do it by putting a text box on the form into which you put the number of records you want - callit Tot. Then a command button, which will open the table as a DAO and then loop until it reaches the value of the text box.

The click event associated with the command button would look something like this:

Sub Writerecs()
Dim db as database
Dim rs as recordset
Dim ind as integer

Set db = currentdb(0
Set rs = db.openrecordset ("yourtable")

For ind = 1 to Me!Tot
rs.addnew
rs.fields("data1") = Me!Data1
rs.fields("DAta2") = Me!Data2
etc, etc

rs.update
Next ind
rs.close
end sub
 
Unfortunately, I am getting a compile error when I execute the command button. I put both the text box and command button in the report footer. Any ideas?
 
If you copied the code literally from mikey69's answer, try changing:
Code:
Set db = currentdb(
0
to
Code:
Set db = currentdb()
(typo)

You may also have to change:
Code:
Dim db as database
Dim rs as recordset
to
Code:
Dim db as dao.database
Dim rs as dao.recordset
and put a "Reference" to "Microsoft DAO 3.x Object Library" under Tools/References

Otherwise, can you tell us what line the error is on?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top