Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Option to select where to save a file.

Posted on 2011-09-28
6
Medium Priority
?
346 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
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
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…

610 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