Avatar of vmccune
Flag for United States of America asked on

filedialog problem


I am using the following code to select a file to process.  It was working fine when I only had one form for searching.  I now have 3 forms in the application using this code and when I run it on a form, it fails and when I check the code, me.filelist is null.  If I use the picker, find the file, use the picker again and find the file again it works fine.  

I have no idea what would cause this other than some hitch in the picker.

Any help is greatly appreciated.

' Requires reference to Microsoft Office 12.0 Object Library. '
   Dim fDialog As Office.FileDialog
   Dim varFile As Variant

   ' Clear listbox contents. '
   Me.FileList.RowSource = ""

   ' Set up the File Dialog. '
   Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

   With fDialog

      ' Allow user to make multiple selections in dialog box '
      .AllowMultiSelect = False

      ' Set the title of the dialog box. '
      .Title = "Please select Style File download to process"

      ' Clear out the current filters, and add our own.'
      '.Filters.Add "Access Databases", "*.MDB"
      '.Filters.Add "Access Projects", "*.ADP"
      .Filters.Add "All Files", "*.*"
      .Filters.Add "Excel Files", "*.XLS*"

      ' Show the dialog box. If the .Show method returns True, the '
      ' user picked at least one file. If the .Show method returns '
      ' False, the user clicked Cancel. '
      If .Show = True Then

         'Loop through each file selected and add it to our list box. '
         For Each varFile In .SelectedItems
            Me.FileList.AddItem varFile

         MsgBox "You clicked Cancel in the file dialog box."
      End If
   End With

End Sub

Open in new window

Microsoft Access

Avatar of undefined
Last Comment

8/22/2022 - Mon

I cannot guess what the problem is from the code you show here.

However, I notice that you do not allow multi-select, yet you seem to use a list box or combo box to return the selected file. Why is that? If the list box is also multi-select, then it would be Null in all cases, else you simply haven't selected the file in the list box yet.

If you only want a single file, replace the list box by a text box. If for some other reason you need the list box, make sure you select the file in it, or the value would be Null, even if the file appears in the list.


Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

I only need one file but I didnt want to go through the effort of maing it work without the row source.

I would really prefer it that way however.

I will try the second item now.

If there is no other reason then yes, please try it with a simple text box instead.

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck

Fixed me right up!