?
Solved

Option to select where to save a file.

Posted on 2011-09-28
6
Medium Priority
?
341 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Expert Comment

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

http://www.lebans.com/callbackbrowser.htm
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

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