troubleshooting Question

filedialog problem

Avatar of vmccune
vmccuneFlag for United States of America asked on
Microsoft Access
5 Comments1 Solution408 ViewsLast Modified:
Hello,

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.Clear
      '.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
         Next

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

End Sub
ASKER CERTIFIED SOLUTION
harfang

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros