Guest_imported
New member
- Jan 1, 1970
- 0
We keep track of our payroll information in a table called "TblWeeklyHours". So, every time an user clicks the "Add a New Week" button, a row is added into the table "TblWeeklyHours", where the Date field is automatically filled in based on the last entered date for a particular school. The new date added is a week from the last entered date.
But Now we want to insert 3 rows into the table "TblWeeklyHours", so I added the FOR...NEXT loop into the code. It inserts 3 rows into the table, but it doesnt keep the date same in those 3 rows.
Is there a way by which when the user clicks the "Add a New Week" button, 3 rows are inserted with the same date based on a week from what the last entered date was.
I might have placed the FOR...NEXT loop in the wrong section of the code but I dont know how to debug since I am new to access programming.
Any input will be appreciated. Thanks.
Here is the code:
-----------------
Private Sub Command6_Click()
Dim db As Database
Dim strDate As String
Dim rstdate As Recordset
Dim rstAddDate As Recordset
Dim strAddDate As String
Dim strPasteSchool
Dim x As Date
Dim y
Dim c
strPasteSchool = " WHERE (((TblWeeklyHours.SchoolLink)=" & SchoolLink & " ))"
y = MsgBox("Click Yes or hit enter to create a new week.", vbYesNo, "Create new week"
If y = vbYes Then
Set db = CurrentDb()
For c = 1 To 3
strDate = "SELECT TOP 1 TblWeeklyHours.SchoolLink, TblWeeklyHours.WeekOf, TblWeeklyHours.Department, TblWeeklyHours.HrsSched, TblWeeklyHours.OTSched FROM TblWeeklyHours" & strPasteSchool & " ORDER BY TblWeeklyHours.WeekOf DESC"
strAddDate = "SELECT * FROM TblWeeklyHours" & strPasteSchool & ""
Set rstAddDate = db.OpenRecordset(strAddDate)
Set rstdate = db.OpenRecordset(strDate)
x = rstdate!WeekOf
rstdate.AddNew
rstdate!WeekOf = DateAdd("d", 7, x)
rstdate!SchoolLink = NoCommaSchoollink
rstdate.Update
rstdate.close
Next c
db.close
Me.Requery
Else
End If
End Sub