Solved

How do I export an MS Access Report to a pdf format via VBA to a slected path

Posted on 2014-09-15
4
5,323 Views
Last Modified: 2014-09-28
I have a few reports I want to export to pdf, but only after being prompted to select the path.  How would I in the below example be prompted each time I export a report to select the path/file for MyPath & Myfilename

DoCmd.OutputTo acOutputReport, "VolunteerRoster", acFormatPDF, Mypath & Myfilename, False, , , acExportQualityPrint...

Would I need to use the DIR command or some form of the Windows scripting file ?
0
Comment
Question by:upobDaPlaya
  • 2
  • 2
4 Comments
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 40324988
I use a function to retrieve the path name:
Public Function GetPath(Optional Message As Variant = Null, Optional ByRef Cancel As Boolean = False) As String

    'Uses the FileDialog object of the Application to select a folder
    With Application.FileDialog(4) 'msoFileDialogFolderPicker
        .AllowMultiSelect = False
        .Title = Nz(Message, "Select a folder")
        .Show

        If .SelectedItems.Count > 0 Then
            GetPath = .SelectedItems(1)
            Cancel = False
        Else
            Cancel = True
        End If

    End With

End Function

Open in new window

Then you can do something like the following in your code:
Dim Cancel as boolean
Dim strMsg as string

strMsg = "Select the folder where you want the file to be saved
myPath = GetPath(strMsg, Cancel)
if Cancel = false then 
    DoCmd.OutputTo acOutputReport, "VolunteerRoster", acFormatPDF, Mypath & Myfilename, False, , , acExportQualityPrint...
End IF

Open in new window

0
 

Author Closing Comment

by:upobDaPlaya
ID: 40335915
Thanks this works ....
0
 

Author Comment

by:upobDaPlaya
ID: 40348089
Actually I do have 1 issue..where/how do I reference myfilename
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40348451
Not sure what you mean?  In the doCmd.OutputTo line, you need to concatenate the path and file name.  That could be something like:

MyPath & "YourFileName.pdf"

Or you could create a string (MyFileName) and assign that a value and use the syntax that I used in the code above.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question