Filters for Save as filedialog (probably revisited) (1 Viewer)

spikepl

Eledittingent Beliped
Local time
Today, 06:28
Joined
Nov 3, 2010
Messages
6,144
A number of postings on the web (and in this Forum) claim that

Application.Filedialog(msoFileDialogSaveAs)

is "problematic" or doesn't work, and point towards a Windows API :


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

In my Access 2007, the Application.Filedialog(msoFileDialogSaveAs)-thinggy works OK. The only thing I am missing is that I have been unable to determine how to set filters for it, so it only displays files of the same type as I am saving. Any hints?
 

jdraw

Super Moderator
Staff member
Local time
Today, 01:28
Joined
Jan 23, 2006
Messages
15,364
I have used the filedialog without issues, but I'm not a real heavy user.
Here's some code I use that shows how to set up filters.

Code:
'---------------------------------------------------------------------------------------
' Procedure : FileDialogThing
' Author    : user
' Date      : 2/27/2009
' Purpose   : To use a File Folder Picker to list existing .txt, .doc , .pdf , .xls and .jpg files
'
' Requires:  Reference to Office 12 Object Library
'
' Returns: a string of the fullpath of the selected file
'
' Last Updated: 5/12/2009
'---------------------------------------------------------------------------------------
'
Function FileDialogThing() As String
    Dim mFileInfoForLater As String
     'Declare a variable as a FileDialog object.
    Dim fd As FileDialog
     
     'Create a FileDialog object as a File Picker dialog box.
   On Error GoTo FileDialogThing_Error

    Set fd = Application.FileDialog(msoFileDialogFilePicker)
     
     'Declare a variable to contain the path
     'of each selected item. Even though the path is aString,
     'the variable must be a Variant because For Each...Next
     'routines only work with Variants and Objects.
    Dim vrtSelectedItem As Variant
     
     'Use a With...End With block to reference the FileDialog object.
     ' and set filters for extensions to list
    With fd
        .Title = "Select File Names"       '<--addition
        .Filters.Add " Files", "*.txt"     '<--addition
        .Filters.Add " Files", "*.doc"     '<--addition
        .Filters.Add " Files", "*.pdf"     '<--addition
        .Filters.Add " Excel", "*.xls"     '<--addition
        .Filters.Add " JPGs", "*.jpg"     '<--addition
        .AllowMultiSelect = False
        .InitialFileName = CurrentProject.Path
         'Use the Show method to display the File Picker dialog box and return the user's action.
         'The user pressed the button.
        If .Show = -1 Then
          
             'Step through each string in the FileDialogSelectedItems collection.
            For Each vrtSelectedItem In .SelectedItems
                 
                 'vrtSelectedItem is a string that contains the path of each selected item.
                 'You can use any file I/O functions that you want to work with this path.
                 'This example displays the path in a message box.
   '****
   'Comment out the acImport stuff
   '  DoCmd.TransferText acImportDelim, "MDBLog_Import Specification", "A2Kmdbs", vrtSelectedItem, True

    mFileInfoForLater = vrtSelectedItem '<<<< assigned for use later
     
    MsgBox "Imported Database Names from: " & vrtSelectedItem
            Next vrtSelectedItem
             
        Else
        End If
        FileDialogThing = mFileInfoForLater
    End With
    'Debug.Print mFileInfoForLater
     'Set the object variable to nothing.
    Set fd = Nothing

   On Error GoTo 0
   Exit Function

FileDialogThing_Error:

    MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure FileDialogThing of Module FileDialog_Picker"
     
End Function
 
Last edited:

spikepl

Eledittingent Beliped
Local time
Today, 06:28
Joined
Nov 3, 2010
Messages
6,144
#2

How do you propose using your code for SAVING a file? I have no problems setting filters when selecting a file to read, just when saving one. Google reveals that I am not the only one with this problem - and the documentatioen I was able to find just says how to see what the filters ARE (when msoFileDialogSaveAs is set for FielDFialog), but not how to SET them.
 

Users who are viewing this thread

Top Bottom