Results 1 to 11 of 11
  1. #1
    Lesg is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    101

    print PDF to folder


    Hi Guys,

    I have the following code to print a copy of a report to a folder using the following code:

    Code:
    Private Sub buttonPreview_Click()
    Dim StrFileName As String
    Dim strReport As String
    
    strReport = "rptInvoice_Dispatch_edit"
    StrFileName = Me.CustName & "_" & Me.invoice & "_" & Me.df1 & ".pdf"
    StrFileName = "C:\Data\temp\" & StrFileName
    
    DoCmd.OpenReport strReport, acViewPreview
    
    Debug.Print
    
    DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, StrFileName, False
    The code errors when trying to save the file, but cannot see why as the location exists and looks like the file name is correct, how can I debug to find the problem, as you can see I have added debug print, but no idea where that output would be, I have the immediate window open?

    Can anyone advise how I can resolve this please.

    Ultimately the file will be saved to a Sharepoint location, but testing locally first.

  2. #2
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Code:
    Debug.Print StrFileName
    Will spit out the StrFileName variable to the immediate window.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    you can also put a stop on the line (f9), hover the cursor over the variable when it stops and a popup will tell you the value.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    Quote Originally Posted by Lesg View Post
    Hi Guys,

    I have the following code to print a copy of a report to a folder using the following code:

    Code:
    Private Sub buttonPreview_Click()
    Dim StrFileName As String
    Dim strReport As String
    
    strReport = "rptInvoice_Dispatch_edit"
    StrFileName = Me.CustName & "_" & Me.invoice & "_" & Me.df1 & ".pdf"
    StrFileName = "C:\Data\temp\" & StrFileName
    
    DoCmd.OpenReport strReport, acViewPreview
    
    Debug.Print
    
    DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, StrFileName, False
    The code errors when trying to save the file, but cannot see why as the location exists and looks like the file name is correct, how can I debug to find the problem, as you can see I have added debug print, but no idea where that output would be, I have the immediate window open?

    Can anyone advise how I can resolve this please.

    Ultimately the file will be saved to a Sharepoint location, but testing locally first.
    You need to debug.print <something>
    The output will be in the immediate window (Ctrl + G)
    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
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,557
    Hi

    One of these is a Filename and the other is a Path

    Code:
    StrFileName = Me.CustName & "_" & Me.invoice & "_" & Me.df1 & ".pdf"
    StrFileName = "C:\Data\temp\" & StrFileName
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    You have not even said what the error is?
    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

  7. #7
    Lesg is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    101
    Hi Guys,

    Thanks for the responses, have been away for a few days, back again now to sort this out.

    Thanks for the suggestions, will try these now and update accordingly.

    @welshgasman the error is nothing is being saved to the folders, it just errors on the path.

  8. #8
    Lesg is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    101
    Quote Originally Posted by Welshgasman View Post
    You need to debug.print <something>
    The output will be in the immediate window (Ctrl + G)
    So have added the function to debug and returns the result I want, i.e. I want this pdf to be saved as per the path below:

    C:\Data\temp\biu Ale Steak Restaurant & Function Rooms_64540_06/09/2022.pdf

    The problem is no file is saved as per the above request, is this due to spaces in the customer name? 'biu Ale Steak Restaurant & Function Rooms' or the date format maybe?

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    Well try replacing the spaces with underscores and see?
    Just as you have done with the suffix.
    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

  10. #10
    Lesg is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Sep 2021
    Posts
    101
    Quote Originally Posted by Welshgasman View Post
    Well try replacing the spaces with underscores and see?
    Just as you have done with the suffix.
    I did try that, ultimately just saving with the invoice, which worked

    So on checking, it was the date format causing the problem, so I will need to format the date, although this is not that important for the client

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    Quote Originally Posted by Lesg View Post
    I did try that, ultimately just saving with the invoice, which worked

    So on checking, it was the date format causing the problem, so I will need to format the date, although this is not that important for the client
    Ah yes, sorry, missed that completely.
    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. Print All Excel Files In A Specific Folder
    By MatthewGrace in forum Programming
    Replies: 1
    Last Post: 11-10-2020, 01:56 PM
  2. Print all PDF Documents in a folder
    By sdel_nevo in forum Programming
    Replies: 7
    Last Post: 03-01-2017, 09:49 AM
  3. Need access vba to Print all pdf from a fix folder
    By Khatuaaccess in forum Access
    Replies: 9
    Last Post: 08-07-2016, 08:35 AM
  4. vba to print all pdfs from a folder
    By Khatuaaccess in forum Access
    Replies: 1
    Last Post: 08-01-2016, 05:17 AM
  5. Replies: 10
    Last Post: 09-09-2015, 03:25 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