To add new records with a loop:
Function MakeData(HowMany As Long)
Dim lngI As Long
Dim rs As DAO.Recordset
Set rs = DBEngine(0)(0).OpenRecordset("MyTable")
With rs
For lngI = 1 To HowMany
.AddNew
!SomeField = SomeValue
!AnotherField = AnotherValue
'etc.
.Update
Next
End With
rs.Close
Set rs = Nothing
End Function
It may be easier to execute one Append query statement, and use a Cartesian
product to generate the desired number of records. That's just a matter of
having a table that counts from 1 to the maximum number of records you would
ever need to add. Include this table in your append query, with no join
between tables. Use criteria under the counter field to get the desired
number of records.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Bob said:
I am trying to insert several records into a table at one time with the
same values. I will collect the default values that I need to have for the
fields in a form and then insert the default values the number of times that
the user puts in a dropdown box. An example of this would be: I collect
StartDate, MealDate, FinishDate, FinishTime, and JobCode and the user enters
a 3 in the dropdown. I want to insert the values that are in those fields 3
times into the same table. I am sure I have to loop through a recordset
somehow but I am under the gun on this and could use some help. The values
that the user has entered on the form are not stored in any table.