I am using the following code to find a source file to load into my application. I need to find and selelct the dialog twice for it to work. as an example:
If I select file "A" and load it when I first open the form, no problem. If I then select file "B" and load, it loads file "A" even though file "B" is displayed in the dialog. If I search and select for file "B" a second time, it then correclty loads file "B".
My guess is somehow I need to refresh something internal to know what file I have selected.
Any help is appreciated.
Private Sub FileList_DblClick(Cancel As Integer)
' 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)
' Allow user to make multiple selections in dialog box '
.AllowMultiSelect = False
' Set the title of the dialog box. '
.Title = "PROFITABILITY UPLOAD"
' 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 "All Files", "*.csv"
' 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
MsgBox "You clicked Cancel in the file dialog box."