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

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » File dialog box shows all file types rather than selected file types

    Author
    Topic
    #489549

    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?

    Viewing 1 reply thread
    Author
    Replies
    • #1395885

      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

    • #1395899

      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.

      • #1395987

        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"
        
    Viewing 1 reply thread
    Reply To: File dialog box shows all file types rather than selected file types

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: