I've gone back to basics and have no end of trouble just by trying to use the MSDN examples. http://msdn.microsoft.com/en-us/libr.../ff196794.aspx
I get an error on the first declaration "Dim fDialog As Office.FileDialog"
I have MS Office Object Library 14. loaded
Code:
Private Sub cmdFileDialog_Click() ' Requires reference to Microsoft Office 11.0 Object Library. Dim fDialog As Office.FileDialog Dim varFile As Variant
I found some code that will work to open the Dialog
Code:
Private Sub cmdFileDialog_Click()
Dim objDialog As Object
Dim varFile As Variant
' Clear listbox contents.
Me.FileList.RowSource = ""
Set objDialog = Application.FileDialog(3)
The problem with the above is that I have to use =Application.FileDialog(3) . If I use =Application.FileDialog(msoFileDialogFilePicker), I get an error.
And finally, I get an error after I make a file selection in the Dialog. I set up a form with a listBox named "FileList"
Code:
Private Sub cmdFileDialog_Click()
Dim objDialog As Object
Dim varFile As Variant
' Clear listbox contents.
Me.FileList.RowSource = ""
Set objDialog = Application.FileDialog(3)
With objDialog
.AllowMultiSelect = True
' Set the title of the dialog box.
.Title = "Please select one or more files"
' 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", "*.*"
' 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
Set objDialog = Nothing
End Sub
I can't understand why every step has an issue, considering the original code came from a reputable source. I didn't have any problems with my folder picker to copy Folder paths, so I wasn't expecting this. Any guidance or a good source for all things FileDialog would be appreciated.