Results 1 to 6 of 6
  1. #1
    chris.williams is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    94

    Automatically Closing Print Preview Window

    Hi all - I am attempting to send a PDF via a DoCmd.SendObject command. One of the requirements is to have the PDF attachment named after a variable field in the report. The only way I have been able to get this to work is through a DoCmd.OpenReport and name the Window what I need the file name to be named.

    The problem exists when the print preview window does not close. If I run another report, the original print preview window is not replaced and the wrong report is sent with the SendObject command. The work around for this is to manually close the print preview window.

    I have tried automatically closing it after the SendObject command with a DoCmd.Close command, but I am unable to close it that way.



    I am looking for either one of two solutions:
    1) a more elegant way of sending a "named" PDF attachment via SendObject or
    2) a way to automatically close the Print Preview window.

    Thanks...

    Code:
    DoCmd.OpenReport "rpt_Certificate", acViewPreview, , , acWindowNormal
    
    DoCmd.SendObject acSendReport, "rpt_Certificate", acFormatPDF, MailTo, _
        MailCC, , Subject, Body, True
    
    DoCmd.Close acReport, [FTSOCertNumber]

  2. #2
    chris.williams is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    94
    I was able to fix the problem through a work around. I have a close window button on the form and an Access macro that does a CloseWindow. It works, but I'd like to have it work in VBA.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    This line:

    DoCmd.Close acReport, [FTSOCertNumber]

    Would have to specify the report name, similarly to when you opened it:

    DoCmd.Close acReport, "rpt_Certificate"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    chris.williams is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    94
    the rpt_Certificate is just a variable for [FTSOCertNumber]. I have the following and none of them work:

    DoCmd.Close acReport, rpt_Certificate
    DoCmd.Close acReport, 'rpt_Certificate'
    DoCmd.Close acReport, "rpt_Certificate"

  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,640
    Did some testing, and it's because you're using the True argument to edit the email. That seems to pause the code. I found that if I send the email, the code then finishes and the report closes.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    chris.williams is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    94
    OK Thanks - I will give that a shot.

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

Similar Threads

  1. Print & Print Preview Differ
    By IDH in forum Reports
    Replies: 3
    Last Post: 07-25-2012, 09:50 AM
  2. Closing a form automatically
    By accessnewb in forum Forms
    Replies: 27
    Last Post: 07-22-2011, 05:58 PM
  3. print preview
    By rmohebian in forum Access
    Replies: 4
    Last Post: 02-14-2011, 08:10 AM
  4. Print Preview different from Print Hardcopy
    By peterc in forum Reports
    Replies: 4
    Last Post: 10-27-2009, 05:35 AM
  5. Error when trying to print or print preview
    By TriAdX in forum Reports
    Replies: 8
    Last Post: 08-25-2009, 08:20 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