Results 1 to 13 of 13
  1. #1
    JulieAHop is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2017
    Location
    Netherlands
    Posts
    15

    Output a report to pdf, defining the default filename from fields on form

    Hi

    I have been trying to put some code behind a button that will allow me to export a pdf report version of what a user has selected on a form, I want the file name to default to fields from the form and I want the user to be able to specify where to save the file. I have stolen bits of code from various places on the internet and have got it to work beautifully with the file names but it doesn't allow the user to browse and specify where they want it saved.

    Private Sub Command61_Click()
    DoCmd.OutputTo acOutputReport, "QuoteView", acFormatPDF, "C:\Users\User\Documents" & _
    Forms![quoteview]![CustName] & "STQ000" & Forms![quoteview]![QuoteNo] & " .pdf"
    End Sub

    Is what I want to do possible?


    Once again, any help would be greatly appreciated. Your help so far has proved invaluable.

    Cheers

    Julie

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    yes, but you missed a slash after documents
    also try for readability:

    vFile = 'C:\Users\User\Documents\' & Forms![quoteview]![CustName] & "STQ000" & Forms![quoteview]![QuoteNo] & " .pdf"
    DoCmd.OutputTo acOutputReport, "QuoteView", acFormatPDF, vFile

  3. #3
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    wow...i keep correcting the slash after \documents\ , but the web keep erasing after i save.
    weird.

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    ranman, looks like you missed it also....

    Code:
    Private Sub Command61_Click()
       vFile =  "C:\Users\User\Documents\" & Forms![quoteview]![CustName]  & "STQ000" & Forms![quoteview]![QuoteNo] & " .pdf"
       Msgbox vFile   ' <<--comment out after it is working
       DoCmd.OutputTo acOutputReport, "QuoteView", acFormatPDF, vFile
    End Sub


    Edit:
    OK, we crossed posts. Looks like it finally took..... very weird...

  5. #5
    JulieAHop is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2017
    Location
    Netherlands
    Posts
    15
    Hi Guys,

    Thanks so much for responding, the gremlins must be out in force because I've corrected that slash after documents too - weird.

    What I was after,(probably didn't explain myself properly - sorry) was the ability for the user to change the path, as when you save a file in word etc but for the filename to default to what i have selected using the field names. Does that make sense??

    Apologies for being vague, I am a total novice and am blowing my mind with what I am doing with the help from good people such as you.

    Thanks

    Julie

  6. #6
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Sounds like you need filedialogue box

    https://m.youtube.com/watch?v=QLoJ0oqaJkM

  7. #7
    JulieAHop is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2017
    Location
    Netherlands
    Posts
    15
    The report is based on selections the form, so I just want to be able for the user to click a button on the form and have a save as dialogue box, which has as default the filename made up from fields on the form & then they can decide where to save it.

    Using the report to file macro, I can get a dialogue box to display, where the default file name is the report name but what I really want is for the file name to default to the two fields.

    Using the vba I can get it to export the pdf with the file name I want but it doesn't give the user the option to select where they want to save it.
    Click image for larger version. 

Name:	Capture1.PNG 
Views:	15 
Size:	59.5 KB 
ID:	27461

  8. #8
    roaftech is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Nov 2012
    Location
    Romania
    Posts
    65
    Hi Julie,
    I am working with Access 2003 and, if I understand your posts correctly, I have a routine which does what you want. It's probably not for the 21st century purists, but you could have a look at my post #18 in the recent " Report to PDF error" thread.
    The filename is generated from data within the report, the report is copied with the new file name and then passed to an external PDF writer which pauses to ask for the save location. Finally the main report is reinstated and the temporary deleted.
    So last century but it works!
    Good luck

  9. #9
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Is this the sort of thing you mean?

    Code:
    Private Sub Command12_Click()
    Dim filetosave As String
    Dim reportrun As String
    reportrun = "tbltilt_full_Crosstab" ' change to reportname to run
    filetosave = "tbltilt" 'play around with to get this to be your filename
    DoCmd.OutputTo acOutputReport, reportrun, acFormatPDF, filetosave, False
    
    End Sub

  10. #10
    JulieAHop is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2017
    Location
    Netherlands
    Posts
    15
    Hi Andy,

    Thanks for your response, I can't get filename to reflect current record fields I want as the default filename.

    Basically the form displays a quote and I want the user to be able to output the related report as a pdf and the when they have clicked the button they get the output to dialogue box where they can select the filepath where they want to output to and the filename defaults as the customer name and the quote number.

    I really appreciate your help, maybe I have too greater expectations of myself. :-)

    Thx Julie

  11. #11
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Dim filename as string
    Filename=me.[custname] & me.[quoteNo]

    Msgbox filename



    Should set filename to the value you want and then show it in a msgbox so you can check it




    Sent from my iPhone using Tapatalk

  12. #12
    JulieAHop is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2017
    Location
    Netherlands
    Posts
    15
    Hi

    It sets the correct filename but doesn't give the option to change the output to filepath.

    Sorry if I am being a complete inbecile with this, I am way out of my depth, a little knowledge is dangerous.

    Thx

  13. #13
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051

    Any use

    andysbrowsing.zip

    Borrowed most from https://access-programmers.co.uk/for...ghlight=browse but I think it should suffice

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

Similar Threads

  1. Replies: 2
    Last Post: 05-09-2015, 07:09 PM
  2. Replies: 2
    Last Post: 07-06-2014, 05:37 PM
  3. Replies: 4
    Last Post: 04-23-2014, 04:35 PM
  4. Replies: 2
    Last Post: 03-18-2013, 03:03 PM
  5. Display the Filename in a Report.
    By GordonT in forum Access
    Replies: 1
    Last Post: 01-27-2013, 08:35 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