Results 1 to 11 of 11
  1. #1
    Niko is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    47

    How to save output file name based on PO Number when exporting to PDF

    Hello guys, how to have the PDF name based on the PO number when it export from access to PDF file?


    Currently, when i click on the button "Export to PDF" on my form to export my purchase order report to report, the file name of the exported PDF file will be save as the same name as my report which is not what i want. Firstly, it is because it might be hard for user to know which file belong to which PO number. Secondly, it will cause lots of duplication files like Report,Report(1),Report(2) and the list goes on. Therefore, I would like to name the PDF file as the PO number before exporting to PDF.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Are you using DoCmd.OutputTo method? Use the OutputFile argument to construct the path\filename with concatenation.

    "path" & Me.PONumber & ".pdf"
    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
    Niko is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    47
    Quote Originally Posted by June7 View Post
    Are you using DoCmd.OutputTo method? Use the OutputFile argument to construct the path\filename with concatenation.

    "path" & Me.PONumber & ".pdf"
    Yes I am. i have error with my code which say "The outputto action was canceled."

    Private Sub cmdSavetoPDF_Click()
    Dim filename As String
    Dim filepath As String


    filename = Me.txtMXDPO.Value
    filepath = "C:\Users\User\Desktop" & filename & ".pdf"
    DoCmd.OutputTo acOutputReport, "MXDReport<Keep>", acFormatPDF, filepath
    MsgBox "Report have been save successfully", vbInformation, "Save confirmed"


    End Sub

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Need another \.

    filepath = "C:\Users\User\Desktop\" & filename & ".pdf"

    Advise not to use spaces nor punctuation/special characters (underscore only exception) in names for anything.
    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
    Niko is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    47
    Quote Originally Posted by June7 View Post
    Need another \.

    filepath = "C:\Users\User\Desktop\" & filename & ".pdf"

    Advise not to use spaces nor punctuation/special characters (underscore only exception) in names for anything.
    Still same error

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    The method works for me.

    You have a user named User?

    What is the value in the textbox?
    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
    Niko is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    47
    Quote Originally Posted by June7 View Post
    The method works for me.

    You have a user named User?

    What is the value in the textbox?
    Yes, because i log in as user.
    The value in the text box = ABC17/101

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Filename can't have / character. Other forbidden characters: \ : * ? " < > |
    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.

  9. #9
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    @June this thread might make you aware that this was mentioned sometime ago... https://www.access-programmers.co.uk...2&postcount=29

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Does look like the same poster even though usernames are different.

    My earlier warning about special characters was intended for Access objects (table, query, form, report, controls). Better would be MXDReport_Keep. Now expand that advice to the structure of PO number, although a hyphen (-) would be acceptable. I use a hyphen for a document ID like: 2017A-0001.

    I create that document ID with VBA as the sequence must restart each year. Review https://www.accessforums.net/showthread.php?t=23329
    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.

  11. #11
    Niko is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    47
    Quote Originally Posted by June7 View Post
    Does look like the same poster even though usernames are different.

    My earlier warning about special characters was intended for Access objects (table, query, form, report, controls). Better would be MXDReport_Keep. Now expand that advice to the structure of PO number, although a hyphen (-) would be acceptable. I use a hyphen for a document ID like: 2017A-0001.

    I create that document ID with VBA as the sequence must restart each year. Review https://www.accessforums.net/showthread.php?t=23329
    I removed and it works now. Thanks

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

Similar Threads

  1. Exporting Form to PDF - Output File Name
    By thexxvi in forum Access
    Replies: 13
    Last Post: 05-26-2015, 07:25 PM
  2. Replies: 1
    Last Post: 11-04-2014, 12:07 PM
  3. Access macro to save query form output
    By sroy in forum Macros
    Replies: 5
    Last Post: 06-14-2013, 01:57 PM
  4. Save As dialog box exporting Excel file
    By accessnewbie in forum Access
    Replies: 1
    Last Post: 03-09-2013, 03:15 PM
  5. auto fill name based on file number
    By mark_w in forum Forms
    Replies: 13
    Last Post: 08-03-2012, 04:59 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