Add multiple similar records with one button click (1 Viewer)

carlosdpr

Registered User.
Local time
Today, 13:11
Joined
May 2, 2016
Messages
16
Hello!

I have a form to register some data from when a group "passes by" a inn to get a stamp when they are doing a peregrination. The data is date, route, path, start local, transport method and number of partners (basically how many people are in the group). I already have a save button that only saves when all the fields have data inserted.

I would like to know if it is possible to, when I click this save button, instead of just saving one record for the group it would save (if the group is 20 people for example) 20 records with the same data and the only thing that will change is the stamp_id. So, I will then have in the stamp table (that has the data I have described above) 20 records with the same data and different stamp_id's.

If I could use the number I put in the text box where I input the number of partners to like count the number of records to save it would be awesome.

Thanks in advance!
 

Ranman256

Well-known member
Local time
Today, 08:11
Joined
Apr 9, 2015
Messages
4,337
Yes ,you could cycle thru a loop, executing an append query for each new stampID....

Code:
BtnSave_click()

  For I= 0 to 20
      vID =txtBoxID +I
      sSql = "append into table (field1, field2) values(" & vID & ",'" & txtBox2 & "')"
      Docmd.runSql sSql
  Next
End sub
 

carlosdpr

Registered User.
Local time
Today, 13:11
Joined
May 2, 2016
Messages
16
That doesn't work very welll.
I don't want always to create 20 records, the amount of records I want to create is equal to the value I put in the number of partners textbox.
The stamp_id is the primary key of my table and an autonumber, so it can't be repeated. So the line vID = txtboxID + I doesn't seem to make sense to me.

What I think will work is, if possible, save the record with the stamp_id (1, for example) and then it loops (saving the same record with stamp_id increasing, 2, 3, 4...) until the value that is in the number of partners textbox is reached. All this by just clicking in the save button...

One important aspect is that, after I save this records, and i reach (for example) stamp_id 20...In the next time I try to add a different record (what I mean is, when I close the form where I insert data and then open it another time to make a new record) it will start in stamp_id 21 or above, and adds the new amount of records based on the new number of partners.
 

Users who are viewing this thread

Top Bottom