I came across this code on a database that i found, and the problem that comes out is that the script is out of range, the code is supposed to be used to attach a filtered report to an email, it does work for me on outlook but i really need it to work with Lotus notes is possible, here is the code:
Option Compare Database
Option Explicit
Public Sub EMailAsPDF(vReport As String, vPDFName As String, vEmail As String, vSubject As String, vBody As String)
'Send Access report/s as a .pdf file to one (or more) e-mail addresses
'Entry (vReport) = Name of report/s (separate with commas for multiple reports)
' (vPDFName) = Name used for PDF file excluding .pdf extension (separate with commas for multiple reports)
' (vEMail) = E-Mail address (separate with semi-colons for multiple E-Mail addresses)
' (vSubject) = Subject string
' (vBody) = Body of E-Mail string
'To send a report/s attached to an e-mail address use code like this in your forms :-
'
' EMailAsPDF "Your Report Name", "Name of PDF file", "Recipients e-mail address", "Subject Line", "Main body of e-mail text"
'
'To send the report to more than one recipient add other e-mail addresses separated by semi-colons. i.e. "Joe@aol.com;Fred@tiscali.co.uk"
'To send more than one report, separate each report AND pdf filename with a comma,
'i.e. EMailAsPDF "ReportName1,ReportName2", "PDF file1,PDF file2", "Recipients e-mail address", "Subject Line", "Main body of e-mail text"
Dim vFolder As String, vDBPath As String, vDBFile As String, vAttachments As String
Dim vReports() As String, vNames() As String
Dim vCount As Long
On Error GoTo ErrorCode
vDBPath = CurrentDb.Name 'fetch full pathname of db folder
vDBFile = Dir(vDBPath) 'extract filename
vFolder = Left(vDBPath, Len(vDBPath) - Len(vDBFile)) 'fetch db folder name
vReports = Split(vReport, ",") 'extract report names to vReports array
vNames = Split(vPDFName, ",") 'extract pdf names to vNames array
For vCount = 0 To UBound(vReports)
If Val(SysCmd(acSysCmdAccessVer)) > 11 Then 'if A2007 or later format then
DoCmd.OutputTo acOutputReport, vReports(vCount), "PDF Format", vFolder & vNames(vCount) & ".pdf", False 'save report to disk as temporary .pdf file
Else
Call ConvertReportToPDF(vReports(vCount), , vFolder & vNames(vCount) & ".pdf", False, False) 'save report to disk as temporary .pdf file
End If
vAttachments = vAttachments & vFolder & vNames(vCount) & ".pdf" & "," 'add report name to attachment string
Next
vAttachments = Left(vAttachments, Len(vAttachments) - 1) 'remove last comma chr
DoEvents
Call SendMail(vEmail, "", "", vSubject, vBody, vAttachments) 'send e-mail (with .PDF file/s attached)
For vCount = 0 To UBound(vReports)
Kill vFolder & vNames(vCount) & ".pdf" 'delete temp file/s
Next
Exit Sub
ErrorCode:
If Err = 2501 Or Err = 2465 Then Exit Sub 'if user cancels e-mail then abort
Beep
MsgBox Err.Description 'else show error
End Sub
Public Function SendMail(strRecipients As String, strCC As String, strBCC As String, strSubject As String, strBody As String, strAttachments As String) As String
'Written by Tom Wickerath, May 7, 2006.
'Entry (strRecipients) = Semi-colon delimited string of recipients.
' (strCC) = Carbon Copy address.
' (strBCC) = Blind Carbon Copy address
' (strSubject) = Message subject.
' (strBody) = Optional. Body of the message.
' (strAttachments) = List of files to attach to e-mail (separated by commas)
Dim myObject As Object, myItem As Object, NS As Object
Dim vCount As Long
Dim vArray() As String
On Error GoTo ProcError
Set myObject = CreateObject("Outlook.Application")
Set NS = myObject.GetNamespace("MAPI")
NS.Logon
Set myItem = myObject.CreateItem(0)
vArray = Split(strAttachments, ",") 'fetch attached filenames into vArray
With myItem
.Subject = strSubject 'enter Subject text
.To = strRecipients 'add recipients email addresses (semi-colon delimited if > 1)
.CC = strCC
.BCC = strBCC
If Len(Trim(strBody)) > 0 Then 'enter message text
' .Body = strBody 'use normal text only
.HTMLBody = strBody 'body text can be HTML type (if reqd)
End If
For vCount = 0 To UBound(vArray) 'scan array
.Attachments.Add (vArray(vCount)) 'add attachment/s
Next
.Display 'open Outlook on screen
' .Send 'this option will do the same as .Display but NOT display e-Mail program
End With
ExitProc:
Set myItem = Nothing
Set myObject = Nothing
Exit Function
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in SendMail Function..."
SendMail = "A problem was encountered attempting to automate Outlook."
Resume ExitProc
Resume
End Function
thanks for all the help.