Results 1 to 5 of 5
  1. #1
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544

    Export then email separate reports issues


    Good morning! I'm at the point of doing the same thing over and over, expecting to get a different result. I need a fresh pair of eyes please. We email an invoice reminder each month. The original statement works perfectly. But (even though I've copied the report and most of the function) the reminder report being emailed includes everyone's statement. Here's the code:
    Code:
    Private Sub Command104_Click()Dim oApp As New Outlook.Application
    Dim oEmail As Outlook.MailItem
    Dim filename As String, todayDate As String
    Dim rst As DAO.Recordset
    Dim LastName As Variant
    Dim strBody As String, lngCount As Long, lngRSCount As Long
    Dim StrTo As String
    Me.AssessmentType1 = "roads"
    DoCmd.OpenQuery "DeleteACCTTABLETEMP"
    DoCmd.OpenQuery "AppendAsmtsandAccountsCurrentRoadstotesttable"
    DoCmd.OpenQuery "ACCOUNTSBALFWDFINALTOTAL"
    
    
    Set rst = CurrentDb.OpenRecordset("SELECT * FROM [EmailRoadsGroupAsmtHeader]ORDER BY [lastname];", dbOpenSnapshot)
    
    
    Do While Not rst.EOF
        strRptFilter = "[memberid_PK] = " & rst![MemberID_PK]
        Debug.Print rst![MemberID_PK]
    
    
        
        DoCmd.OpenReport "EmailRoadsAssessmentReminder", acViewPreview
        DoCmd.OutputTo acOutputReport, "EmailRoadsAssessmentReminder", acFormatPDF, "C:\HAH Database FE\Emailtests" & "\" & rst![MemberID_PK] & "REMINDERroads.pdf"
        DoCmd.Close acReport, "EmailRoadsAssessmentReminder"
        
        DoEvents
    
    
    
    
    Set oEmail = oApp.CreateItem(olMailItem)
    With oEmail
    
    
          StrTo = rst!InvoiceEmail
          filename = "C:\HAH Database FE\Emailtests" & "\" & rst![MemberID_PK] & "REMINDERroads.pdf"
         Debug.Print filename
    
    
        Debug.Print rst!InvoiceEmail
        .TO = StrTo
        Debug.Print StrTo
        Debug.Print filename
        .Subject = "Roads Statement Attached"
        .Body = "Thank you"
        .Attachments.Add filename
        .Display
        rst.MoveNext
    '
    '
    End With
    Loop
    MsgBox "Email successfully sent!", vbInformation, "EMAIL STATUS"
    
    
    
    
    End Sub
    The data is correct, but again, each members' statement includes all members' statements. I hope this is clearer than mud. TIA!

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    You need to filter the OpenReport to the relevant customer. You create a filter, but do not use it?
    Examine the syntax for OpenReport.

    Plus that question is asked multiple times, see similar threads or a search of this site.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    Thank you Welshgasman, I'm sure a lot of the previous questions are from me too! I did try to search, but I don't think I phrased the question correctly. Thanks for your time, I got it sorted out. Have a great day!

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    So please post the code that works now. It might help someone else in the future, and that is what this site is about.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    I went at it a different way, so it really wouldn't be helpful to anyone else I'm afraid.

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

Similar Threads

  1. Generate Separate PDF Export By Group
    By hfreedman1957 in forum Reports
    Replies: 11
    Last Post: 02-21-2017, 09:59 PM
  2. Replies: 13
    Last Post: 02-08-2017, 04:11 PM
  3. Table of Contents for 2 separate Reports
    By pharrison74 in forum Reports
    Replies: 70
    Last Post: 03-01-2016, 08:47 AM
  4. Replies: 3
    Last Post: 08-16-2013, 04:15 PM
  5. Print Separate Reports with collate
    By HendriX99 in forum Reports
    Replies: 3
    Last Post: 02-04-2011, 07:46 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