[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

msoFileDialogFilePicker doesn't list files

I have an procedure which is supposed to allow the user to choose which text file is to be imported into the application for processing.  It uses msoFileDialogFilePicker in a seperate sub-procedure to accomplish this.  The problem is that when the user navigates to the proper folder no files are visible in the folder, although they are definitely there.  I have commented out the line in the sub-procedure which originally applied a filter to msoFileDialogFilePicker.  I call the sub with the following lines of code:
MsgBox "Select MLPA4 Text File"
    strMlpa4Path = GetLocation()
    MsgBox "Select MLPA6 Text File"
    strMlpa6Path = GetLocation()

And the sub looks like this:
Public Function GetLocation()

Dim fd As FileDialog
    Dim objfl As Variant
    Dim filename As String

    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
        .ButtonName = "Select"
        .AllowMultiSelect = False
        '.Filters.Add "All Files", "*.*"
        .Title = "Choose File to Import"
        .InitialView = msoFileDialogViewDetails
        .Show
    For Each objfl In .SelectedItems
        GetLocation = objfl
    Next objfl
   
    On Error GoTo 0
    End With
End Function
0
cekendricks
Asked:
cekendricks
  • 4
  • 3
  • 2
  • +2
1 Solution
 
Aaron TomoskyTechnology ConsultantCommented:
Looks like you have a stray single quote before the filters.add line
0
 
Rey Obrero (Capricorn1)Commented:
try this revision

Public Function GetLocation() as string

Dim fd As FileDialog
    Dim objfl As Variant
    Dim filename As String

    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
        .ButtonName = "Select"
        .AllowMultiSelect = False
        '.Filters.Add "All Files", "*.*"
        .Title = "Choose File to Import"
        .InitialView = msoFileDialogViewDetails
       
    if .Show=-1 then
    For Each objfl In .SelectedItems
        GetLocation = objfl
    Next objfl
    end if
    On Error GoTo 0
    End With
End Function

Open in new window

0
 
Rey Obrero (Capricorn1)Commented:
oops, hit the submit button too soon
try this revision
Public Function GetLocation() as string

Dim fd As FileDialog
    Dim objfl As Variant
    Dim filename As String

    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
        .ButtonName = "Select"
        .AllowMultiSelect = False
        .Filters.Add "All Files", "*.*"
        .Title = "Choose File to Import"
        .InitialView = msoFileDialogViewDetails
       
    if .Show=-1 then
    For Each objfl In .SelectedItems
        GetLocation = objfl
    Next objfl
    end if
    On Error GoTo 0
    End With
End Function

Open in new window

0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
cekendricksAuthor Commented:
I commented out that line on purpose, because I thought it might be the cause of the problem...I wanted to eliminate filters as the possible cause.  Another thing that I forgot to mention, is that eventhough I have the .filter line commented out, when the filepicker comes up it still lists *.xlsx in the filename box.
0
 
cekendricksAuthor Commented:
I am still getting the same behavior with the revised code.  What puzzles me is the filepicker seems to still be trying to filter for *.xlsx files.  The button lists All files *.*, as I would expect, but the filename box still lists *.xlsx
0
 
TinTombStoneCommented:
This works for me.
Since you have set AllowMultiSelect to False
I'm just picking up the one selected file
GetLocation = .SelectedItems(1)

or returning False if the count = 0

Function GetLocation() As String
Dim fd As FileDialog

    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
        .ButtonName = "Select"
        .AllowMultiSelect = False
        .Filters.Add "All Files", "*.*"
        .Title = "Choose File to Import"
        .InitialView = msoFileDialogViewDetails
        .Show

        If .SelectedItems.Count <> 0 Then
            GetLocation = .SelectedItems(1)
        Else
            GetLocation = "False"
        End If
    End With
End Function
0
 
TinTombStoneCommented:
Sorry, one more thing

Try FD.Filters.Clear

to get rid of existing filters before you add new ones
0
 
cekendricksAuthor Commented:
Thanks for you suggestion TombStone, but I am still getting the same results.  I cannot seem to clear the .xlsx filter, and since the requested folder only contains .txt files, nothing is showing up.  I have searched ALL of my code to see if there might possible be an old GetLocation function laying around, and there is not...I am now in the process of searching the two involved modules for any references to .xlsx  That's all I can think of to do at this time, other than just adding the code for the GetLocation function to the procedure that is using it.
0
 
Rey Obrero (Capricorn1)Commented:
try doing this

try doing compact and repair
office button >manage > compact and repair database

if problem persists,
* do a decompile
   see this link
http://www.granite.ab.ca/access/decompile.htm

* after decompiling, open the VBA window and do
     Debug > Compile
     correct any errors raised

* do a compact and repair

* test your codes

0
 
cekendricksAuthor Commented:
I think I've found a solution.  In searching through the rest of my code I noticed that I have another function called SaveLocation.  This is also a file picker type function that I use to select a save location for exported files.  In that function I saw that with fd there is a method .InitialFileName = "*.xlsx"  I thought that that might be what was setting GetLocation's initial file name, so I commented it out of the SaveLocation function.  Well this had no effect.  So I inserted .InitialFileName = "*.*" in my GetLocation function, and 'Lo and Behold', it now see's all the files in the folders.  I will be testing further, but at least it worked the first time I tried it.
0
 
Eileen MurphyIndependent Application DeveloperCommented:
.InitialFileName = "*.*" worked for me too!!!! I was going crazy! Thank you!!!!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now