Hi,
I'm generating a vacation report for each of my employees to be e-mailed to them in house. The code is below.
The recordset is rendered invalid by the OutputTo command. (I originally thought it was the call to the e-mail function, but it's not.)
Becuase the report is different for each record in the recordset I need the OutputTo inside the loop to generate a unique report for each record ... OR I need another method of generating the report for e-mail delivery.
Does anybody have any ideas?? I've tried using DoEvents and moving the MoveNext command above the DoCmd line. It doesn't matter. Once the OutputTo is executed, the next line that references the recordset returns the invalid recordset error.
Thanks!
Joe
I'm generating a vacation report for each of my employees to be e-mailed to them in house. The code is below.
The recordset is rendered invalid by the OutputTo command. (I originally thought it was the call to the e-mail function, but it's not.)
Becuase the report is different for each record in the recordset I need the OutputTo inside the loop to generate a unique report for each record ... OR I need another method of generating the report for e-mail delivery.
Does anybody have any ideas?? I've tried using DoEvents and moving the MoveNext command above the DoCmd line. It doesn't matter. Once the OutputTo is executed, the next line that references the recordset returns the invalid recordset error.
Thanks!
Joe
Code:
Private Sub cmdEmailAllRpts_Click()
'To send a vacation update report by email to all employees
'MsgBox "This code doesn't work yet. Call out to Outlook renders recordset invalid."
'Exit Sub
Dim MyDB As Database, MyRecs As Recordset
Dim strSQL, strSubject, strMessage, strAlias As String
If IsNull(Me.txtBalanceDate) Then
MsgBox "You must choose a balance date for the end of the report."
Me.txtBalanceDate.SetFocus
Exit Sub
End If
strSubject = "Vacation Balance Update Report"
strMessage = "Please review the attached report and report any inaccuracies immediately."
strSQL = "SELECT EmployeeID, ExchangeAlias FROM Employees"
strSQL = strSQL & " WHERE Current = True AND MoVacHrsAccrue > 0"
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set MyRecs = MyDB.OpenRecordset(strSQL, dbOpenDynaset)
MyRecs.MoveFirst
Do Until MyRecs.EOF
strAlias = MyRecs![ExchangeAlias]
Me.cboEmp = MyRecs![EmployeeID]
DoCmd.OutputTo acOutputReport, "rptVacationHours", acFormatRTF, "c:\VacationRpt.htm", False
fctnOutlook , strAlias, , , strSubject, strMessage, , , False, "c:\VacationRpt.htm"
MyRecs.MoveNext
Loop
MyRecs.Close
MyDB.Close
End Sub