I am trying to update a single record at a time through a loop. But on the first trip through the loop it tries to update all the records at once. I am trying to update a list of records that have a start date and end date, starting with a user given date that is stored in a table. Here is my code:
Dim dbsSubwayDB As DAO.Database
Dim rstSettings As DAO.Recordset
Dim rstWEDates As DAO.Recordset
Set dbsSubwayDB = CurrentDb
Set rstSettings = dbsSubwayDB.OpenRecordset("tblSettings")
Set rstWEDates = dbsSubwayDB.OpenRecordset("tblW_E_Dates")
WkEndngDay = rstSettings!WeekEndingDay
Sql = "UPDATE tblsettings SET Weekendingday = " & cboWeekDay.ListIndex & ";"
DoCmd.RunSQL Sql
StartDate = #1/1/2006# + WkEndngDay
rstWEDates.MoveFirst
For I = 1 To 8
EndDate = StartDate + 6
Sql2 = "UPDATE tblW_E_Dates SET StartDate = " & StartDate & ", EndDate = " & EndDate & ";"
DoCmd.RunSQL Sql2
EndDate = EndDate + 7
StartDate = StartDate + 7
rstWEDates.MoveNext
Next I
The red is the update that is updating everything at once. There are no errors, just not doing what I want it to do...
Oh...and all I'm getting in my table is a time with no date (12:00:03 AM)
Dim dbsSubwayDB As DAO.Database
Dim rstSettings As DAO.Recordset
Dim rstWEDates As DAO.Recordset
Set dbsSubwayDB = CurrentDb
Set rstSettings = dbsSubwayDB.OpenRecordset("tblSettings")
Set rstWEDates = dbsSubwayDB.OpenRecordset("tblW_E_Dates")
WkEndngDay = rstSettings!WeekEndingDay
Sql = "UPDATE tblsettings SET Weekendingday = " & cboWeekDay.ListIndex & ";"
DoCmd.RunSQL Sql
StartDate = #1/1/2006# + WkEndngDay
rstWEDates.MoveFirst
For I = 1 To 8
EndDate = StartDate + 6
Sql2 = "UPDATE tblW_E_Dates SET StartDate = " & StartDate & ", EndDate = " & EndDate & ";"
DoCmd.RunSQL Sql2
EndDate = EndDate + 7
StartDate = StartDate + 7
rstWEDates.MoveNext
Next I
The red is the update that is updating everything at once. There are no errors, just not doing what I want it to do...
Oh...and all I'm getting in my table is a time with no date (12:00:03 AM)
Last edited: