Solved

Option to select where to save a file.

Posted on 2011-09-28
6
335 Views
Last Modified: 2013-11-27
I have a form that uses a list box (lstReports) where the user selects the report to print, email or save. The following code is used to save the selected report to PDF, however it automatically saves it somewhere, I want to give the user the option to save it where they want,or at least hard-code where to save, I am using Access 2007. Any help would be greatly appreciated.  
Private Sub btnSavePDF_Click()
On Error GoTo btnSavePDF_Click_Err
Dim stDocName2 As String

stDocName2 = Me.lstReports
  
DoCmd.OutputTo acOutputReport, stDocName2, acFormatPDF, _
    stDocName2 & Format(Date, "yyyy-mm-dd") & ".pdf", True

btnSavePDF_Click_Exit:
    Exit Sub

btnSavePDF_Click_Err:
    MsgBox Error$
    Resume btnSavePDF_Click_Exit
End Sub

Open in new window

0
Comment
Question by:skull52
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:DerZauberer
ID: 36716413
I think if you completely leave out the name it will ask the user where to save:

DoCmd.OutputTo acOutputReport, stDocName2, acFormatPDF,, True

Of coz you can specify full path programmatically if you like:

DoCmd.OutputTo acOutputReport, stDocName2, acFormatPDF, "C:\TEMP\Whatever.pdf", True
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 36716650
try this code, in the File Name you need to type in at least a letter or a number (doesn't matter what, it will not be included in the file name, some sort of cheating :-) )


Private Sub btnSavePDF_Click()
On Error GoTo btnSavePDF_Click_Err
Dim stDocName2 As String

stDocName2 = Me.lstReports
 
'****

Dim fd As Object, strFile As String
Set fd = Application.FileDialog(2)
With fd
    .AllowMultiSelect = False
    .ButtonName = "Save File"
    .InitialView = 1
    .Title = "Save File As"
    If .Show Then
        strFile = .SelectedItems(1)
    End If
End With
strFile = Left(strFile, InStrRev(strFile, "\"))
strFile = strFile & stDocName2 & Format(Date, "yyyy-mm-dd") & ".pdf"


'******



DoCmd.OutputTo acOutputReport, stDocName2, acFormatPDF, strFile, True

btnSavePDF_Click_Exit:
    Exit Sub

btnSavePDF_Click_Err:
    MsgBox Error$
    Resume btnSavePDF_Click_Exit
End Sub


0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 36716706
you can also try the codes from this link, download the zip file

http://www.lebans.com/callbackbrowser.htm
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:skull52
ID: 36716769
Thanks Cap, the code works but it is a little ambiguous I think for a user, is there anyway to just hard-code the file location and have it save the current file name.
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 36716833
you can try using this

dim strFile as string

 strFile= environ("userProfile") & "\folderName\" & stDocName2 & Format(Date, "yyyy-mm-dd") & ".pdf"


as the starting path to save the file ( change "folderName" with the actual name of folder )
0
 

Author Comment

by:skull52
ID: 36717771
Cap that did the trick, thanks as always
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

948 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

23 Experts available now in Live!

Get 1:1 Help Now