?
Solved

msoFileDialogFilePicker doesn't list files

Posted on 2011-03-03
11
Medium Priority
?
673 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 39

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…
Suggested Courses

770 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