I've been stuck on this for a week now! I have a form and a subform:
-Mainform-
EmployID(PriKey- from Employees Table)
controlling
-subform-
DayPK(PriKey HIDDEN),DayID(dates), EmployID,Day(names)
This is for a timecard database. I want to be able to add days (records) to each employee. Very similar to adding invoices to employees. I want all the records I create in code to be copied to ALL employees when I push the button. The end result is I can add a whole week of records to each employee for data entry.
The code I've got so far takes the last DayID (Date) entered increases it's value by one day and creates the new record. The next bit of code moves to the next employee and replicates the created record (without increasing the date).
I KNOW you can loop this so it will create new records for each of my employees till the EOF but I can't get the debugger to take it. I thought of using a query to count the number of employees and run the loop x many times but I'm getting an undefined record error.
Please help...first time doing this kind of VB stuff.
Thanks a TON,
Nick
My code follows:
Private Sub AddWeek_Click()
Dim rsta As Recordset
Dim rstb As Recordset
Dim str As String
Dim i As Long
Dim e As Long
Set rsta = CurrentDb.OpenRecordset("Employees", dbOpenDynaset)
Set rstb = CurrentDb.OpenRecordset("Days", dbOpenDynaset)
rstb.MoveLast
i = rstb![DayID] + 1
str = rsta![EmployID]
rstb.AddNew
rstb![DayID] = i
rstb![EmployID] = str
rstb![Day] = "Wednesday"
rstb.Update
rsta.MoveNext
str = rsta![EmployID]
rstb.MoveLast
i = rstb![DayID]
rstb.AddNew
rstb![DayID] = i
rstb![EmployID] = str
rstb![Day] = "Wednesday"
rstb.Update
Me.[Days subform].Requery
End Sub
-Mainform-
EmployID(PriKey- from Employees Table)
controlling
-subform-
DayPK(PriKey HIDDEN),DayID(dates), EmployID,Day(names)
This is for a timecard database. I want to be able to add days (records) to each employee. Very similar to adding invoices to employees. I want all the records I create in code to be copied to ALL employees when I push the button. The end result is I can add a whole week of records to each employee for data entry.
The code I've got so far takes the last DayID (Date) entered increases it's value by one day and creates the new record. The next bit of code moves to the next employee and replicates the created record (without increasing the date).
I KNOW you can loop this so it will create new records for each of my employees till the EOF but I can't get the debugger to take it. I thought of using a query to count the number of employees and run the loop x many times but I'm getting an undefined record error.
Please help...first time doing this kind of VB stuff.
Thanks a TON,
Nick
My code follows:
Private Sub AddWeek_Click()
Dim rsta As Recordset
Dim rstb As Recordset
Dim str As String
Dim i As Long
Dim e As Long
Set rsta = CurrentDb.OpenRecordset("Employees", dbOpenDynaset)
Set rstb = CurrentDb.OpenRecordset("Days", dbOpenDynaset)
rstb.MoveLast
i = rstb![DayID] + 1
str = rsta![EmployID]
rstb.AddNew
rstb![DayID] = i
rstb![EmployID] = str
rstb![Day] = "Wednesday"
rstb.Update
rsta.MoveNext
str = rsta![EmployID]
rstb.MoveLast
i = rstb![DayID]
rstb.AddNew
rstb![DayID] = i
rstb![EmployID] = str
rstb![Day] = "Wednesday"
rstb.Update
Me.[Days subform].Requery
End Sub