Results 1 to 4 of 4
  1. #1
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    File dialog box shows all file types rather than selected file types

    Code is:
    Code:
        '   get code for pic
        Dim vFile, sPath2Pics, FileChosen
        vFile = file
        sPath2Pics = CurrentProject.Path
        With Application.FileDialog(msoFileDialogFilePicker)
            .Filters.Clear
            FileChosen = .Show
             .Title = "Choose File"
             .InitialFileName = sPath2Pics & "\pics\"
            
            .InitialView = msoFileDialogViewList
             .Filters.Clear
            
            .Filters.Add Description:="JPG files (*.jpg)", Extensions:="*.jpg"
            .Filters.Add Description:="PDF files (*.pdf)", Extensions:="*.pdf"
            .ButtonName = "Choose this file"
            .AllowMultiSelect = False
             .FilterIndex = 1
        
            If FileChosen <> -1 Then
                MsgBox "No file chosen !!"
            Else
                file = .SelectedItems(1)
            End If
        End With
    The above code shows all files (*.*) in the file dialog box, why is this so?
    What does .FilterIndex = 1 do?

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts
    As it turns out i have solved it by replacing:
    .Filters.Add Description:="JPG files (*.jpg)", Extensions:="*.jpg"
    .Filters.Add Description:="PDF files (*.pdf)", Extensions:="*.pdf"
    to
    .Filters.Add Description:="Select files (*.jpg,*.png)", Extensions:="*.jpg;*.pdf"

    The All file *.* in the file types at the bowwom don't matter

  3. #3
    2 Star Lounger
    Join Date
    Dec 2009
    Location
    Manchester, United Kingdom
    Posts
    116
    Thanks
    8
    Thanked 17 Times in 16 Posts
    I'm surprised you fixed it like that way, the basic problem is that your initial code shows the dialog before you set it's properties. Set the properties then show the dialog just before you test the return value.

    Setting FilterIndex tells the dialog which filter, when you provide multiple filters, is the default. i.e. the one selected before the user drops down the list of filters and selects another.

    Ian.

  4. #4
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts
    Thanks Ian, would you change my code and let me know what you mean please
    No matter i did the following:
    Code:
             .Title = "Choose File"
             .InitialFileName = sPath2Pics & "\pics\"
            
            .InitialView = msoFileDialogViewList
             .Filters.Clear
            
            .Filters.Add Description:="JPG files (*.jpg)", Extensions:="*.jpg"
            .Filters.Add Description:="PDF files (*.pdf)", Extensions:="*.pdf"
             FileChosen = .Show
            .ButtonName = "Choose this file"
    Last edited by patt; 2013-06-11 at 09:10.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •