Results 1 to 3 of 3
  1. #1
    Mattbro is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    95

    Combining 'sending mail' with 'sending a report'.

    Hello Everybody,
    Using Access 2003, I have a database that on_click, generates a report and opens up outlook, from which I manually populate the message address in outlook.
    I have found some useful code that allows me to automatically email on_click, all senders whose address exists within a table from http://www.jephens.com/2007/05/13/ho...using-outlook/. which works perfectly. so now........I am trying to combine the two.
    Code for sending reports as per command button wizard;


    Code:
    Private Sub ReportSend_Click()Dim stDocName As String
    stDocName = "Breach"
    DoCmd.SendObject acReport, stDocName
    Exit_ReportSend_Click:
    Exit Sub
    The code for the second database resides in a module and is instigated as a macro running off a command button
    Code:
    Public Function SendEMail()
    Dim db As DAO.Database
    Dim MailList As DAO.Recordset
    Dim MyOutlook As Outlook.Application
    Dim MyMail As Outlook.MailItem
    Dim Subjectline As String
    Dim BodyFile As String
    Dim fso As FileSystemObject
    Dim MyBody As TextStream
    Dim MyBodyText As String
    Set fso = New FileSystemObject
    Subjectline$ = "Breach"
    MyBodyText = "Please find report attached"
    If 1 = 2 Then
    BodyFile$ = "InputBox"
    Set MyBody = fso.OpenTextFile(BodyFile, ForReading, False, TristateUseDefault)
    MyBodyText = MyBody.ReadAll
    MyBody.Close
    End If
    Set MyOutlook = New Outlook.Application
    Set db = CurrentDb()
    Set MailList = db.OpenRecordset("MyEmailAddresses")
    Dim MyRecip As Outlook.Recipient
    Do Until MailList.EOF
    Set MyMail = MyOutlook.CreateItem(olMailItem)
    Set MyRecip = MyMail.Recipients.Add(MailList("email"))
    MyRecip.Type = olBCC
    MyMail.Subject = Subjectline$
    MyMail.Body = MyBodyText
    'MyMail.Attachments.Add "c:myfile.txt", olByValue, 1, "My Displayname"
    Dim MyQuery As QueryDef
    Set MyQuery = CurrentDb.QueryDefs("ReportSource")
    MyQuery.SQL = "select * from emails "
    MyQuery.Close
    MyMail.Send
    MailList.MoveNext
    Loop
    Set MyMail = Nothing
    MyOutlook.Quit
    Set MyOutlook = Nothing
    MailList.Close
    Set MailList = Nothing
    db.Close
    Set db = Nothing
    End Function

    Does anybody know if it is possible to incorporate the former code in the second passage to cause the email to contain the report? The original code shows where (as stated in green text', but how to I redirect this to the report? Any pointers very gratefully received.
    Mattbro

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    The second email method would require saving the report as a pdf and then including the pdf as an attachment to the email. Can use OutputTo method to save as pdf.
    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
    Mattbro is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Mar 2012
    Posts
    95
    Ah-right youare. It almost works, but not with PDFs. Access 2003 doesn't like creating them from reports for some reason. I have coded two buttons on the form-one to generate the report
    Code:
    DoCmd.OutputTo acOutputReport, "Breach", acFormatRTF, "C:\BreachOutput\Breach.rtf", False
    And added the line on the second button
    Code:
    MyMail.Attachments.Add "C:\BreachOutput\Breach.rtf", olByValue, 1, "My Displayname"
    Job done! Thanks for the input, June7
    Mattbro

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

Similar Threads

  1. Replies: 3
    Last Post: 04-15-2012, 05:25 PM
  2. Sending Report via E-mail Error
    By Nettie in forum Access
    Replies: 8
    Last Post: 04-06-2012, 12:15 PM
  3. Replies: 11
    Last Post: 09-12-2011, 11:30 AM
  4. Sending Outlook E-mail - Run-time error '429'
    By jgelpi16 in forum Programming
    Replies: 2
    Last Post: 03-01-2011, 09:30 AM
  5. Sending mail automatically
    By carstenhdk in forum Forms
    Replies: 1
    Last Post: 05-31-2010, 04:23 PM

Tags for this Thread

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