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
4,923 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now