Results 1 to 5 of 5
  1. #1
    manic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    63

    function question

    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.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Which line throws the error?

    Have you step debugged? Follow the code as it executes, see where deviates from expected behavior, fix, repeat. Let us know how it goes.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    manic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    63
    Alright, I got it to work with outlook. I noticed i was missing the file name on the table where the function reads the name from. now with all that said, how can i use such code to work with lotus notes if possible?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Google: Access VBA email lotus notes

    Here is one http://www.fabalou.com/VBandVBA/lotusnotesmail.asp
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    manic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    63
    thank you.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Question; Count function ..
    By efleming in forum Queries
    Replies: 4
    Last Post: 05-27-2011, 08:05 AM
  2. Max function???
    By kaite07 in forum Queries
    Replies: 1
    Last Post: 11-10-2010, 05:20 PM
  3. Function Help
    By th3spankst3r in forum Programming
    Replies: 12
    Last Post: 03-22-2010, 12:41 PM
  4. Want function to get current function name
    By Davis DeBard in forum Programming
    Replies: 2
    Last Post: 08-13-2009, 05:02 AM
  5. function key
    By marianne in forum Access
    Replies: 5
    Last Post: 05-14-2009, 01:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums