Results 1 to 4 of 4
  1. #1
    StefanJTD is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2017
    Posts
    3

    Problems when cancelling email with PDF report attached

    Hi all,

    As you probably can see I'm new to this forum. My apologies if my English has some (major) flaws.

    I have been working on an Access database, more or less based on an existing one, but in a different way.

    Everything is running very well, but I noticed one problem that causes us to send a specific supplier of us a wrong quality analysis report.

    I will try to give a short version of what happens and when it happens:

    * We enter some values in a form, which are obviously stored in a table;
    * When everything is entered, we click on a button to send an email with a quality analysis attached (as a PDF);
    * Quality analysis is based on a specific record;


    * When e-mail is generated with the attachment added we can send it without any problem;

    Now the catch!

    * When we cancel the e-mail, in the background the report is ofcourse generated and keeps excisting with specific record/data mentioned in this e-mail;
    * When we go to another record and want to send the new quality analysis, the e-mail is generated with the old quality analysis attached.

    What I want is the generated report to be cancelled when I cancel the e-mail. Now the report only looses the "filter" when the e-mail is sent.

    Maybe this question has to be placed in the report section of this forum, but I keep thinking that this is caused by the VB for sending the email (see below).

    Code:
    Private Sub Knop239_Click()
    On Error GoTo Err_Knop239_Click
    
    
       Dim strReportName As String
       Dim strCriteria As String
       Dim strEmailto As String
       Dim strMessageEmail As String
       
       strReportName = "Quality Analysis"
       strCriteria = "[CONTRACTNR]='" & Me!CONTRACTNR & "'"
       strEmailto = Me.E_MAIL
       strMessageEmail = "Dear Supplier," & _
            vbNewLine & vbNewLine & _
            "Enclosed you find our Quality Analysis of the last delivery." & _
            vbNewLine & vbNewLine & _
            "If we send an outturn sample to you because of some remarks, please reply within 5 working days after receiving the sample. We kindly ask you to e-mail your reply to XXX, XXX and XXX." & _
            vbNewLine & vbNewLine & _
            "With kind regards," & _
            vbNewLine & vbNewLine & _
            "XXX" & _
            vbNewLine & _
            "XXX" & _
            vbNewLine & _
            "XXX"
            
       DoCmd.OpenReport strReportName, acViewPreview, , strCriteria, acWindowNormal
       DoCmd.SendObject acSendReport, strReportName, acFormatPDF, strEmailto, "XXX;XXX;XXX", , "Quality Analysis " & Me.CONTRACTNR & " " & Me.LEVERANC, strMessageEmail
       DoCmd.Close acReport, strReportName, acSaveNo
        
    Exit_Knop239_Click:
        Exit Sub
    
    
    Err_Knop239_Click:
      Select Case Err  'specific Case statements for errors we can anticipate, the "Else" catches any others
        Case 2501       'Action OpenReport was cancelled.
          MsgBox "Klik op Afdrukvoorbeeld sluiten!"
          DoCmd.Hourglass False
          Resume Exit_Knop239_Click
        Case Else
          MsgBox Err.Description
          DoCmd.Hourglass False
          Resume Exit_Knop239_Click
      End Select
    End Sub
    * Please note that I'm not at all a VBA and/or Access specialist. I know the basics, but not more than that.

    Thank you all in advance for your help!

    Kind regards,
    Stefan

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Try including the CloseReport command in the Exit_Knop239_Click: exit handler.
    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
    StefanJTD is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2017
    Posts
    3
    Thanks, but can you clarify a little bit more? I'm not really sure what or how to..

  4. #4
    StefanJTD is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2017
    Posts
    3
    Quote Originally Posted by June7 View Post
    Try including the CloseReport command in the Exit_Knop239_Click: exit handler.
    It seems to work!

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

Similar Threads

  1. Replies: 2
    Last Post: 04-09-2014, 12:21 AM
  2. send email with attached image in body
    By trevor40 in forum Programming
    Replies: 5
    Last Post: 02-14-2014, 01:17 AM
  3. Replies: 5
    Last Post: 03-28-2012, 01:22 PM
  4. Creating a Report with Pages Attached
    By qbc in forum Reports
    Replies: 5
    Last Post: 01-12-2012, 01:28 PM
  5. Email Reports Problems
    By Bamber in forum Reports
    Replies: 1
    Last Post: 05-12-2010, 08: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