Results 1 to 6 of 6
  1. #1
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170

    "Send Email" button on Query-Based Report


    Hello Everybody,

    The creation of this database has been a great journey and I hope that we are nearing its completion and off to new and interesting challenges.

    Aside from cosmetic changes, one of the last things that I need to implement is a "Send Email" button. I have seen lots of documentation on this but have not been able to piece it all together.

    Is it possible to create a button to a query-generated Report and then have that button's "Click Event" be the emailing of that report to that person?

    If so can someone walk me through the VBA code to do this (I am VBA novice).

    I have employee ID information stored in fields: "First Name", "Org ID", "Email" under table: "tblNames"

    Thanks so much

  2. #2
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Were you wanting the button to be on the report, on the ribbon when the report is being displayed, or on the form that launches the report?

  3. #3
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170
    On the ribbon would be the best.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,893
    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
    athyeh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jun 2013
    Posts
    170
    This seems to be pretty complicated and may be above my understanding right now. I am going through VBA tutorials would putting a button on a report be "easier"?

  6. #6
    Dal Jeanis is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Here's the code that would go behind a button named cmdMailReport on the form. This assumes that the report is an existing report.
    Code:
    Private Sub cmdMailReport_Click()
    On Error GoTo Err_cmdMailReport_Click
    
        Dim stDocName As String
        Dim stToEmail As String
        Dim stSubject As String
        Dim stBody As String
    
        stDocName = "MyReportName"
        stToEmail = "recipient1@sample.com;recipient2@sample.com"    
        stSubject = "MyReportName For " & Format(Date(), "mm/dd/yyyy")
        stBody = "MyReportName Is Attached for your Review as/of " & Format(Date(), "mm/dd/yyyy")
    
        DoCmd.SendObject acReport, stDocName, acFormatPDF, stToEmail, , ,stSubject, StBody
    
    Exit_cmdMailReport_Click:
        Exit Sub
    
    Err_cmdMailReport_Click:
        MsgBox Err.Description
        Resume Exit_cmdMailReport_Click
        
    End Sub
    I've put in a default subject line, body test and recipients, but you don't have to code those, you could let the user put them in themselves.

    Check this page for all the options on the SendObject command http://msdn.microsoft.com/en-us/libr.../ff197046.aspx

    Here's the general format:
    .SendObject(ObjectType, ObjectName, OutputFormat, To, Cc, Bcc, Subject, MessageText, EditMessage, TemplateFile)

    OutputFormat for a report can be either PDF format (acFormatPDF)or RTF format (acFormatRTF)

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

Similar Threads

  1. Export "Query or Report" to a "Delimited Text File"
    By hawzmolly in forum Import/Export Data
    Replies: 3
    Last Post: 08-31-2012, 08:00 AM
  2. Replies: 11
    Last Post: 03-29-2012, 02:32 PM
  3. Replies: 0
    Last Post: 01-11-2012, 12:34 PM
  4. Replies: 1
    Last Post: 05-23-2011, 08:07 AM
  5. Replies: 6
    Last Post: 03-10-2011, 11:31 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