I am trying to use the below code from my cmd button on my form to insert multiple new records in tblForecast.
I need it to loop through each set of entries and insert a new record (tblForecast has an autonumber ID field)
This code inserts only the 1st new record 5 times instead of inserting all of them once. I have been looking at "loops" but have not figured out if that is the way I should be going, any ideas? I've attached a screenshot of my form.
Private Sub cmdUpdate_Click()
Dim MyDB As DAO.Database
Dim rst As DAO.Recordset
Dim numRecords As Integer
Dim i As Integer
Set MyDB = CurrentDb
Set rst = MyDB.OpenRecordset("tblForecast", dbOpenDynaset, dbOpenAppendOnly)
For i = 1 To 6
With rst
rst.AddNew
![forecastmonth] = Me![txtForecastMonth]
![forecast] = Me![txtForecast]
![division] = Me![cboDiv]
![Group] = Me![cboGroup]
rst.Update
End With
Next i
MsgBox (i + 1) & " Records have been added to the Table [tblForecast]", _
vbInformation, "Append Data"
rst.Close
Set rst = Nothing
End Sub
Thank you! Toni