Solved

msoFileDialogFilePicker doesn't list files

Posted on 2011-03-03
11
612 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 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
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
 

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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 119

Accepted Solution

by:
Rey Obrero 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now