The routine to create and mail reports is called Main and is contained in the Reports module. The relevant code is described as follows.
Log on to MAPI
'Result = MAPILogon(0, "", "", MAPI_LOGON_UI, 0, gSession) 'If Result <> SUCCESS_SUCCESS Then Exit Sub
Create a report and output to Microsoft Excel format
DoCmd OutputTo A_REPORT, "Project Summary", A_FORMATXLS, "C:\~TEMP.XLS"
Initialize MAPI variables
ReDim gRecipients(0) ReDim gFiles(0) gMessage.RecipCount = 1 gMessage.FileCount = 1
Specify the Microsoft Excel file attachment
gFiles(0).Reserved = 0 gFiles(0).Flags = 0 gFiles(0).Position = 0 gFiles(0).pathname = "c:\~temp.xls" gFiles(0).filename = "Reports.xls" gFiles(0).FileType = ""
Specify the Recipient (manager)
gRecipients(0).Name = rs("Manager") gRecipients(0).RecipClass = MAPI_TO
Specify the Subject (NoteText is set to one space so the space can be replaced with the file attachment)
gMessage.Subject = "Weekly Report" gMessage.NoteText = " "
Send the message by calling MAPISendMail
Result = MAPISendMail(gSession, 0, gMessage, gRecipients(0), gFiles(0), 0, 0)
Log off MAPI
Result = MAPILogoff(gSession, 0, 0, 0)