Solved

Option to select where to save a file.

Posted on 2011-09-28
6
334 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
Comment Utility
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
Comment Utility
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
Comment Utility
you can also try the codes from this link, download the zip file

http://www.lebans.com/callbackbrowser.htm
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:skull52
Comment Utility
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
Comment Utility
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
Comment Utility
Cap that did the trick, thanks as always
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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…
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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now