Solved

msoFileDialogFilePicker doesn't list files

Posted on 2011-03-03
11
634 Views
Last Modified: 2013-05-29
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
Comment
Question by:cekendricks
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 38

Expert Comment

by:Aaron Tomosky
ID: 35027331
Looks like you have a stray single quote before the filters.add line
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35027335
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
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35027352
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:cekendricks
ID: 35027438
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
 

Author Comment

by:cekendricks
ID: 35027660
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
 
LVL 6

Expert Comment

by:TinTombStone
ID: 35027853
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
 
LVL 6

Expert Comment

by:TinTombStone
ID: 35027928
Sorry, one more thing

Try FD.Filters.Clear

to get rid of existing filters before you add new ones
0
 

Author Comment

by:cekendricks
ID: 35028169
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
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 35028218
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
 

Author Comment

by:cekendricks
ID: 35028431
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
 

Expert Comment

by:Ei0914
ID: 39206301
.InitialFileName = "*.*" worked for me too!!!! I was going crazy! Thank you!!!!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question