Results 1 to 12 of 12
  1. #1
    Vetgeorge is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2012
    Location
    Florida
    Posts
    29

    I've searched for solutions on emailing from Access and cannot find a solution

    I read countless threads about emailing from Access and tried some of the methods. However, I haven't found a thread that fits the criteria I would like


    I now know I need to loop through a recordset of email addresses to get the multiple addresses into the "To:" field in Outlook.

    I have a report and would like that one report sent as a PDF attachment to multiple recipients based on the query that is the source of the report. So, only people listed in the report will get an email. I would like to use the docmd sendobject method, since I have used it before for simpler emailing at work (one recipient), and I know it works for everyone in the office.

    here is the code I have currently on the command button in the report. It works, but leaves the To field in Outlook blank. I would like the email addresses inserted automatically from the query

    Private Sub cmdEmail_Click()
    On Error GoTo cmdEmail_Click_Err

    DoCmd.SendObject acReport, "rptPendingResolution", "PDFFormat(*.pdf)", "", "", "", "Pending Resolutions requiring your attention", "Please see attachment", True, ""

    cmdEmail_Click_Exit:
    Exit Sub


    cmdEmail_Click_Err:
    MsgBox Error$
    Resume cmdEmail_Click_Exit

    End Sub


    I can post a simple version of the database if necessary.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    You might want to use BCC for multiple emails. Depends on your recipients. Should they be able to see each other's email address?


    Fairly simple to open recordset object, loop records, concatenate address field. The trick is reproducing the report filter.

    How are you filtering the report records? Do users enter criteria into controls on form? Is there a query object with dynamic parameters (I never user dynamic parameterized query)?

    Something like:
    Code:
    Dim rs As DAO.Recordset
    Dim strAdd As String
    Set rs = CurrentDb.OpenRecordset("SELECT Email FROM Employees WHERE DepartmentID =" & Me.cbxDept)
    While Not rs.EOF
        strAdd = strAdd & rs!Email & ";"
        rs.MoveNext
    Wend
    strAdd = Left(strAdd, Len(strAdd)-1)
    Last edited by June7; 03-04-2018 at 01:14 PM.
    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.

  4. #4
    Vetgeorge is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2012
    Location
    Florida
    Posts
    29

    Thanks Orange

    I've seen samples like that which requires someone to manually add addresses. I would rather make it more "automated," since people could forget to add someone to the list or add someone that doesn't need to see the attachment. I had thought of trying something like that as a solution.

  5. #5
    Vetgeorge is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2012
    Location
    Florida
    Posts
    29

    June, thanks for responding

    It doesnt matter if the recipients see the address of others, they all work in the same department. My query for the report is straightforward and doesn't require any input from the users. I have a table for the events (various fields for input), and other tables for comboboxes (not related to any email function), and a table for the user (name/email address)
    Report:
    Click image for larger version. 

Name:	report.jpg 
Views:	24 
Size:	113.9 KB 
ID:	32869
    query for report
    Click image for larger version. 

Name:	rptqry.jpg 
Views:	24 
Size:	117.4 KB 
ID:	32870
    another view query for report
    Click image for larger version. 

Name:	rptqry2.jpg 
Views:	24 
Size:	208.2 KB 
ID:	32871
    subquery from report query to group email addresses
    Click image for larger version. 

Name:	emailqry.jpg 
Views:	24 
Size:	83.1 KB 
ID:	32872
    another view of the subquery
    Click image for larger version. 

Name:	emailqry2.jpg 
Views:	24 
Size:	88.6 KB 
ID:	32873

  6. #6
    Vetgeorge is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2012
    Location
    Florida
    Posts
    29

    Here is a simplified version of the database

    with fake names, made up email addresses
    Attached Files Attached Files

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Before I download db, have you attempted code as I suggested?
    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.

  8. #8
    Vetgeorge is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2012
    Location
    Florida
    Posts
    29
    Let me preface my answer with "I'm a vb amateur" I tried your example, but I am getting an error:

    So then I tried changing the line to:
    Set rs = CurrentDb.OpenRecordset("SELECT Email FROM tblUsers WHERE UserID =" &

    which got rid of the error. Now, how would I incorporate this into my existing code:
    DoCmd.SendObject acReport, "rptPendingResolution", "PDFFormat(*.pdf)", "", "", "", "Pending Resolutions requiring your attention", "Please see attachment", True, ""
    Attached Thumbnails Attached Thumbnails 2018-03-04_093205.jpg  

  9. #9
    Vetgeorge is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2012
    Location
    Florida
    Posts
    29
    Update, after further searching, I found this post in Programming: https://www.accessforums.net/showthr...0send%20object

    His post marked as solved, so I modified his code since it was exactly my scenario which is to email one pdf attachment to multiple recipients:

    Code:
    Sub cmdMail_Click()
    
    Dim rs As Recordset
            Set rs = CurrentDb.OpenRecordset("select [Email] from qryReportEmail")
            If rs.RecordCount > 0 Then
            rs.MoveFirst
            Do Until rs.EOF
                If IsNull(rs![Email]) Then
                rs.MoveNext
                Else
                    strAddresses = rs![Email] & ";" & strAddresses
                    rs.MoveNext
            End If
            Loop
            End If
    
    
    DoCmd.SendObject acSendReport, "qryPendingResolution", "PDFFormat (*.pdf)", strAddresses, "", "", "Pending Resolutions requiring your attention", "Please see attachment", True, ""
    
    
    End Sub

    But when I try it, I get a Runtime error 2059, Access cannot find the object '|1' What am I missing??

  10. #10
    Vetgeorge is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2012
    Location
    Florida
    Posts
    29

    Solved!

    The error was coming from the incorrectly named report in my doCmd line. Once I fixed it, it worked!
    The addresses listed in the report are inserted
    Click image for larger version. 

Name:	2018-03-04_093206.jpg 
Views:	22 
Size:	83.9 KB 
ID:	32882

    Here is the code:
    Code:
    Sub cmdMail_Click()On Error GoTo cmdEmail_Click_Err
    Dim rs As Recordset
            Set rs = CurrentDb.OpenRecordset("select [Email] from qryReportEmail")
            If rs.RecordCount > 0 Then
            rs.MoveFirst
            Do Until rs.EOF
                If IsNull(rs![Email]) Then
                rs.MoveNext
                Else
                    strAddresses = rs![Email] & ";" & strAddresses
                    rs.MoveNext
            End If
            Loop
            End If
    
    
    DoCmd.SendObject acSendReport, "rptPendingResolution", "PDFFormat (*.pdf)", strAddresses, "", "", "Pending Resolutions requiring your attention", "Please see attachment", True, ""
    
    
    cmdEmail_Click_Exit:
        Exit Sub
    
    
    cmdEmail_Click_Err:
        MsgBox Error$
        Resume cmdEmail_Click_Exit
    End Sub
    Last edited by Vetgeorge; 03-04-2018 at 10:34 AM. Reason: Added error lines for cancelling the command

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    And sorry for typo in my suggested code. Now edited.


    However, can simplify the code by only retrieving records that have an email address:

    Set rs = CurrentDb.OpenRecordset("SELECT [Email] FROM qryReportEmail WHERE NOT [Email] Is Null")
    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.

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

Similar Threads

  1. DB hosting solutions
    By ahill48 in forum Access
    Replies: 8
    Last Post: 08-20-2017, 10:26 AM
  2. Solutions for reaching data limits?
    By drr1970 in forum Access
    Replies: 3
    Last Post: 08-08-2017, 06:52 PM
  3. How to find next searched record ???
    By ksor in forum Forms
    Replies: 8
    Last Post: 02-26-2017, 09:20 AM
  4. Multiuser Access Solutions?
    By GaryE in forum Access
    Replies: 4
    Last Post: 04-16-2013, 06:15 AM
  5. Characters before searched string
    By cleme1q in forum Access
    Replies: 4
    Last Post: 12-10-2011, 11:22 AM

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