Results 1 to 8 of 8
  1. #1
    Tonyb123 is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2023
    Posts
    8

    Emailing with a Single Report in attached pdf.


    Hi,
    Send object code works well to attach a pdf file to an email from a button click on a form.
    The issue I'm having, is the attached pdf contains several reports, and not just the "current open form" report.
    How can I modify the code below to only send the report that relates to the open form?
    Thankyou

    Code:
     Private Sub EmailBtn_Click()
    On Error GoTo ErrHandler
    DoCmd.SendObject acSendReport, "HoseTestReport", acFormatPDF, Forms!frmHoseDetails!EmailAddress, , , _
    " Hose Test Details " & TestSerial & " Attached ", "Please find your Hose Test Report attached."
    Exit Sub
    ErrHandler:
        If Err = 2501 Then
            ' User canceled the message - ignore this
        Else
            ' Report the error
            MsgBox Err.Description, vbExclamation
        End If
    End Sub

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Create the correct report first?
    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
    Tonyb123 is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2023
    Posts
    8
    Hi Welshgasman,

    The Report with the correct Serial ID opens for printing correctly, this works as expected. It's only when using the emailing button on the "frmHoseDetails" form that all the saved records are loaded into a single pdf attachment. I.e. the pdf has multiple reports sitting in the pdf browser.

    Thankyou

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    How does report print for correct record(s)?

    What do you mean by relates to "current open form"? Code outputs report you name. Do you need to filter it?

    Options:

    1. Report bound to query that has filter criteria referencing form control for parameter

    2. Report Filter property references form control for criteria and FilterOnLoad set to yes

    3. Open report filtered to desired record(s) with WHERE argument of OpenReport then run SendObject.
    DoCmd.OpenReport
    DoCmd.SendObject
    DoCmd.Close
    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
    Tonyb123 is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2023
    Posts
    8
    Hi June7,

    Thank you for you reply. I agree there is a filtering issue. Additional test: I setup a button on the reports form:[] DoCmd.OpenReport "HoseTestReport", acViewPreview [\] and noted the wrong report opens. If I use a button for a print macro, it opens the correct record for printing. The report has been tested bound to a query and also the forms table. Both yield the same result, wrong record.
    One of your suggestions was to setup filter criteria in the reports query. Please provide an example of the query filter so I can give it a test. Every record has a unique number "TestSerial"

    Thankyou.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Don't really understand much of that. How can it be "wrong report"? It can only open what you tell it to. Do you mean wrong record?

    Is this what you asked for?

    SELECT * FROM sometable WHERE TestSerial=Forms!myformname!mytextboxname


    If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  7. #7
    Tonyb123 is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2023
    Posts
    8
    Hi June7,

    Solved. The form had a glitch. Set the form property Popup to "No" and everything is working correctly. I.e. Reports only show the open form record. Emailed pdf also only displays the form record and no others.

    Possibly the glitch was caused by some vba code i have to prevent form edits. The user must push a button to edit records on the form. The code also changes the tab form name to EDIT Mode. What I hadn't realized was the form name was now slightly different to the browser form name possibly causing issues with the form filtering. Hope that makes sense.

    Thanks for your time on this.

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    I believe if the filtering cannot be realised, then it is ignored. That is probably the reason now you have mentioned this.
    Could always test using the correct naming path for when the tab gets changed?
    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

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

Similar Threads

  1. Replies: 5
    Last Post: 04-14-2022, 09:14 AM
  2. Need to Attached PDF File to Report
    By Sunny8760 in forum Reports
    Replies: 10
    Last Post: 08-16-2018, 10:13 AM
  3. How to included attached files to a report
    By AccessSLC in forum Reports
    Replies: 1
    Last Post: 10-20-2017, 08:40 AM
  4. Multiple invoices attached single job
    By lpkorn423 in forum Reports
    Replies: 3
    Last Post: 07-18-2012, 12:30 PM
  5. Creating a Report with Pages Attached
    By qbc in forum Reports
    Replies: 5
    Last Post: 01-12-2012, 01:28 PM

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