Hi
I'm trying to store the location of a file chosen by the user using the file chooser dialogue box. This code is taken from Microsoft. However, the MS code shows it for a list box. I just want it to store 1 file location in 1 field, called FileList.
Here is the code: The bit is red is the part I have changed to return the filename. However, instead of returing the filename/path it returns "FileDialog(msoFileDialogFilePicker)" in the field.
How do I get the actual path & filename returned into the field?
Thanks
Gary
Private Sub cmdFileDialog___Click()
' This requires a reference to the Microsoft Office 11.0 Object Library.
Dim fDialog As Office.FileDialog
Dim varFile As Variant
' Set up the File dialog box.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Set the title of the dialog box.
.Title = "Select File"
' Clear out the current filters, and then add your 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
Me.FileList = .Item
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
End Sub
I'm trying to store the location of a file chosen by the user using the file chooser dialogue box. This code is taken from Microsoft. However, the MS code shows it for a list box. I just want it to store 1 file location in 1 field, called FileList.
Here is the code: The bit is red is the part I have changed to return the filename. However, instead of returing the filename/path it returns "FileDialog(msoFileDialogFilePicker)" in the field.
How do I get the actual path & filename returned into the field?
Thanks
Gary
Private Sub cmdFileDialog___Click()
' This requires a reference to the Microsoft Office 11.0 Object Library.
Dim fDialog As Office.FileDialog
Dim varFile As Variant
' Set up the File dialog box.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Set the title of the dialog box.
.Title = "Select File"
' Clear out the current filters, and then add your 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
Me.FileList = .Item
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
End Sub