Hello all:
I need help with a code to automate the sending of a report with lotus notes. I have found this code:
Code:
Option Compare Database
Option Explicit
Public mobjDB As Object
Public Sub SEND_EMAILS()
'open the session with the lotus notes server
'this sub will output a report as a file
'attach the file and add the predetermined subject and body
'delete the file that was output
'close the session with the server
If OPEN_SESSION Then
'output report to text file on C:\
'DoCmd.OutputTo acOutputReport, "My Report", acFormatRTF, "O:\Report", False
'put your do loop here
'reference the email report sub to mail the file
If EMAIL_REPORT("MyWonderfulEmailAddress@gmail.com", "My Email Body", "My Subject Line", "O:\Report.pdf") = True Then
MsgBox "Message Sent"
Else
'error in email module
End If
'end your loop here
'delete the file
Kill ("o:\Report.pdf")
'call the close session sub to destroy the objects
CLOSE_SESSION
Else
'session not opened properly
End If
End Sub
Public Function OPEN_SESSION() As Boolean
Dim objSession As Object
Dim strServer As String
Dim strMailFile As String
'lotus notes must be open for module to work correctly
If MsgBox("Do you have lotus notes running?", vbCritical + vbYesNo, "Warning!") = vbYes Then
'this code must be left out of the loop so that only one session is started
Set objSession = CreateObject("Notes.NOTESSESSION")
strServer = objSession.GETENVIRONMENTSTRING("mailserver", True)
strMailFile = objSession.GETENVIRONMENTSTRING("mailfile", True)
Set mobjDB = objSession.GETDATABASE(strServer, strMailFile)
OPEN_SESSION = True
Else
MsgBox "Please start Lotus Notes and try again.", vbOKOnly, "Emails"
OPEN_SESSION = False
End If
End Function
Public Function EMAIL_REPORT(strSendTo As String, strBody As String, strSubject As String, Optional strFile As String) As Boolean
On Error GoTo EmailReport_Err
Dim objDoc As Object
Dim objRichTextAttach As Object
Dim objRichTextItem As Object
Dim objAttachment As Object
Const NOTES_RECIPIENTS = ""
Const NOTES_REPORTS_ADMIN_USER = ""
Const NOTES_MAIL_FILE = "O:\Report.pdf"
Set objDoc = mobjDB.CREATEDOCUMENT
Set objRichTextAttach = objDoc.CREATERICHTEXTITEM("File")
Set objRichTextItem = objDoc.CREATERICHTEXTITEM(objDoc, "Body")
If strFile <> "" Then
Set objAttachment = objRichTextAttach.EMBEDOBJECT(1454, "", strFile)
End If
'set up the email to be sent
objRichTextItem.AppendText strBody
objDoc.REPLACEITEMVALUE "SendTo", strSendTo
objDoc.REPLACEITEMVALUE "Subject", strSubject
objDoc.SaveMessageOnSend = True 'send E-mail
objDoc.SEND False 'false for do not attach a form
EMAIL_REPORT = True
Exit_Here:
Set objAttachment = Nothing
Set objDoc = Nothing
Set objRichTextAttach = Nothing
Set objRichTextItem = Nothing
Exit Function
EmailReport_Err:
EMAIL_REPORT = False
Resume Exit_Here
End Function
Public Sub CLOSE_SESSION()
Set mobjDB = Nothing
End Sub
The problem I have with this code is that it sends an email behind the scenes and i can't see it on my sent files.
How can I adjust this code to just open lotus notes with the attachment in it already so I can manually choose to who I send the report to instead of having it hardcoded.
any help with this will be appreciated.