Solved

Option to select where to save a file.

Posted on 2011-09-28
6
338 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

762 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