[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1068
  • Last Modified:

Application.FileDialog(msoFileSaveAs)

I am trying to set filters for a FileSaveAs dialog using the following code:
    Dim fDialog As Office.FileDialog

    Dim varSelection As Variant
    Dim strFileName As String

    Set fDialog = Application.FileDialog(msoFileDialogSaveAs)
    With fDialog
        .Title = "Select Destination File"
        .InitialFileName = CurrentProject.Path & "\test.pdf"
       
        .Filters.Clear
        .Filters.Add "PDF Files", "*.PDF"

        .Show
    End With

I get an error on the .Flters.Clear line, as well as the Filters.Add line. Everything works fine without those lines of code, but of course I don't get my desired filter. What am I missing?
0
TechMommy
Asked:
TechMommy
1 Solution
 
Dave BrettCommented:
VBA help says that you can't use Clear or Add with SaveAs   ... which isn't very helpful

So you need a workaround. I'm a Excel guy so there you would use GetSaveAsFilename. Not relevant I believe in Access, so a Access workaround would appear to be something like this

http://www.mvps.org/access/api/api0001.htm

hth

Dave
0
 
Jeffrey CoachmanCommented:
<No points wanted>

A benefit of using brett's link is that it will work in versions of Access where you could not use the code you posted.
0
 
TechMommyAuthor Commented:
I was hoping that there was a better/simpler solution, but apparently there isn't. This is certainly an excellent workaround for the problem.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now