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,559 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
Comment Utility
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
Comment Utility
Thanks this works ....
0
 

Author Comment

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

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

771 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

9 Experts available now in Live!

Get 1:1 Help Now