Results 1 to 6 of 6
  1. #1
    cebrower is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Spring Lake, MI
    Posts
    110

    Email from VBA fails to attach report


    I have a routine in VBA that is supposed to create a report in PDF format and send an email with the report attached to our accounting manager when a certain form is closed. It works fine when I test it from my PC, but not from our production manager's PC. In fact, the report itself is not even created from the production manager's PC. Our email is handled by Exchange 2010. I have the full version of Access 2010 on my PC and the front end is in accdb format. The production manager has the run-time version of Access and the front end is in accde format. We both use Outlook 2010. Any ideas? The code is attached.
    Attached Files Attached Files

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    For starters, comment out the "On Error..." line and see what error is produced. Even better, use proper error handling:

    http://www.baldyweb.com/ErrorTrap.htm

    What you've got simply suppresses errors, you want them handled.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    cebrower is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Spring Lake, MI
    Posts
    110
    I realize there is not proper error handling in this routine, but it works just fine when I run it on my PC in ACCDB format with the full version of Access. On a PC running the ACCDE format with Access run-time, the email is delivered, but without the attachment. Also, in the ACCDE format, most errors are suppressed because I run "DoCmd.SetWarnings False" in the Open event of the main menu form so the user doesn't have to confirm every action query, etc.

  4. #4
    cebrower is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Spring Lake, MI
    Posts
    110
    After adding the error checking (Thanks to pbaldy), I discovered that the DoCmd.OutputTo command was failing when the database is in ACCDE format. Turns out that the report must be open for the OutpuTo command to run.

    varReportName = “MyReport”
    DoCmd.OpenReport "rptMyReport", acViewPreview
    DoCmd.OutputTo acOutputReport, "rptMyReport", acFormatPDF, "c:\FolderName" & varReportName & ".pdf"
    DoCmd.Close acReport, "rptIMyReport"

    Make sure the Pop Up property is set to No in the report definition or the report will appear when you open it.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Glad it helped. Curious though, as I use accde format extensively, and I often have OutputTo without opening the report first. Here's a line from a db I happen to have open (strMaster contains a path):

    DoCmd.OutputTo acOutputReport, "rptMasterLeaseAgreement_Sig", acFormatPDF, strMaster

    It has not been opened at this point. I only open it first if I need to use the wherecondition argument.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    cebrower is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2018
    Location
    Spring Lake, MI
    Posts
    110
    We have 25 PCs on our LAN running ACCDE databases. There is only one where I need to open the report in order to have OutputTo succeed. There must be something hinky about that PC.

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

Similar Threads

  1. Attach Database to Email
    By SSgtBarry in forum Access
    Replies: 2
    Last Post: 08-10-2014, 08:42 PM
  2. Attach Report to Email
    By teebumble in forum Reports
    Replies: 5
    Last Post: 11-28-2012, 05:42 PM
  3. Replies: 2
    Last Post: 12-28-2011, 09:32 PM
  4. Can't attach to email
    By newtoAccess in forum Access
    Replies: 10
    Last Post: 12-03-2010, 02:10 PM
  5. Attach Email to Form
    By Huddle in forum Access
    Replies: 2
    Last Post: 07-22-2010, 12:39 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