Hello,
I'm trying to update a table called EmployeeTask_FTE with insert statements via vba. I have two recordsets based on queries:
rs_FTEforupdate based on:
where FTE_outyears_TEMPselectnames selects names based on some criteria I want.
rs_datesforupdate is based on a query that selects some dates out of a table.
These queries run ok. The vba code that uses these two recordsets is below. The problem is that the first Do While loop stops after the first iteration- the entries are inserted only for one person (though the dates loop runs ok).
Debug.print of the recordcounts of the two recordsets gives the correct number. Can someone help me to see why my loop is stopping short?
Thank you!
Code:
I'm trying to update a table called EmployeeTask_FTE with insert statements via vba. I have two recordsets based on queries:
rs_FTEforupdate based on:
PHP:
SELECT employeetask_FTE.lastname, employeetask_FTE.firstname, servicesubcat, Worktimetype, FTE, FTEEntryType
FROM employeetask_FTE INNER JOIN FTE_outyears_TEMPselectnames ON (employeetask_FTe.firstname= FTE_outyears_TEMPselectnames.firstname) AND (employeetask_FTe.lastname= FTE_outyears_TEMPselectnames.lastname)
WHERE FTEmonthstart= #6/1/2012#;
rs_datesforupdate is based on a query that selects some dates out of a table.
These queries run ok. The vba code that uses these two recordsets is below. The problem is that the first Do While loop stops after the first iteration- the entries are inserted only for one person (though the dates loop runs ok).
Debug.print of the recordcounts of the two recordsets gives the correct number. Can someone help me to see why my loop is stopping short?
Thank you!
Code:
PHP:
Sub Insert_outyear_FTE()
Dim qdf_FTEforupdate As QueryDef
Set qdf_FTEforupdate = CurrentDb.QueryDefs!FTE_outyears_TEMPS_subcatsFTEs_to_insert
Dim rs_FTEforupdate As DAO.Recordset
Set rs_FTEforupdate = qdf_FTEforupdate.OpenRecordset
Dim qdf_datesforupdate As QueryDef
Set qdf_datesforupdate = CurrentDb.QueryDefs!FTE_outyears_TEMPS_datesforupdate
Dim rs_datesforupdate As DAO.Recordset
Set rs_datesforupdate = qdf_datesforupdate.OpenRecordset
rs_FTEforupdate.MoveLast
rs_datesforupdate.MoveLast
Debug.Print rs_FTEforupdate.RecordCount
Debug.Print rs_datesforupdate.RecordCount
rs_FTEforupdate.MoveFirst
rs_datesforupdate.MoveFirst
DoCmd.SetWarnings False
Do Until rs_FTEforupdate.EOF = True
Do While Not rs_datesforupdate.EOF = True
DoCmd.RunSQL "Insert into EmployeeTask_FTE (servicesubcat, lastname, firstname, worktimetype, FTE, " & _
"FTE_last_modified_date, FTEMonthStart, FTEMonthEnd, FTEEntryType) values " & _
"('" & rs_FTEforupdate!ServiceSubcat & "', '" & rs_FTEforupdate!LastName & "', '" & rs_FTEforupdate!FirstName & "', '" & _
rs_FTEforupdate!worktimetype & "', " & rs_FTEforupdate!FTE & ", #" & Now() & "#, #" & _
rs_datesforupdate!startdatepar & "#, #" & rs_datesforupdate!enddatepar & "#, '" & rs_FTEforupdate!FTEEntryType & "');"
rs_datesforupdate.MoveNext
Loop
rs_FTEforupdate.MoveNext
Loop
DoCmd.SetWarnings True
End Sub
Last edited: