'---------------------------------------------------------------------------------------
' Procedure : FileDialogThing
' Author : user
' Date : 2/27/2009
' Purpose : To use a File Folder Picker to list existing .txt, .doc , .pdf , .xls and .jpg files
'
' Requires: Reference to Office 12 Object Library
'
' Returns: a string of the fullpath of the selected file
'
' Last Updated: 5/12/2009
'---------------------------------------------------------------------------------------
'
Function FileDialogThing() As String
Dim mFileInfoForLater As String
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
'Create a FileDialog object as a File Picker dialog box.
On Error GoTo FileDialogThing_Error
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'Declare a variable to contain the path
'of each selected item. Even though the path is aString,
'the variable must be a Variant because For Each...Next
'routines only work with Variants and Objects.
Dim vrtSelectedItem As Variant
'Use a With...End With block to reference the FileDialog object.
' and set filters for extensions to list
With fd
.Title = "Select File Names" '<--addition
.Filters.Add " Files", "*.txt" '<--addition
.Filters.Add " Files", "*.doc" '<--addition
.Filters.Add " Files", "*.pdf" '<--addition
.Filters.Add " Excel", "*.xls" '<--addition
.Filters.Add " JPGs", "*.jpg" '<--addition
.AllowMultiSelect = False
.InitialFileName = CurrentProject.Path
'Use the Show method to display the File Picker dialog box and return the user's action.
'The user pressed the button.
If .Show = -1 Then
'Step through each string in the FileDialogSelectedItems collection.
For Each vrtSelectedItem In .SelectedItems
'vrtSelectedItem is a string that contains the path of each selected item.
'You can use any file I/O functions that you want to work with this path.
'This example displays the path in a message box.
'****
'Comment out the acImport stuff
' DoCmd.TransferText acImportDelim, "MDBLog_Import Specification", "A2Kmdbs", vrtSelectedItem, True
mFileInfoForLater = vrtSelectedItem '<<<< assigned for use later
MsgBox "Imported Database Names from: " & vrtSelectedItem
Next vrtSelectedItem
Else
End If
FileDialogThing = mFileInfoForLater
End With
'Debug.Print mFileInfoForLater
'Set the object variable to nothing.
Set fd = Nothing
On Error GoTo 0
Exit Function
FileDialogThing_Error:
MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure FileDialogThing of Module FileDialog_Picker"
End Function