Good Morning,
I am attempting to store a file or folder location in a text field from a dialog box. I would like the ability to choose lets say a .pdf file and store the file path in a text field or just choose a folder and store that folders file path in a text field.
Here is my code so far:
Private Sub Electronic_File_Location_DblClick(Cancel As Integer)
' Requires reference to Microsoft Office 11.0 Object Library.
Dim FileDialog As FileDialog
Dim Filelocation As String
Set FileDialog = Application.FileDialog(msoFileDialogFilePicker)
With FileDialog
.AllowMultiSelect = False
.Title = "Please select one file"
If .Show = True Then
selectedFile = FileDialog.SelectedItems(1)
[Electronic File Location].Value = selectedFile
End If
End With
End Sub
With this code I am forced to select a file directly and it will store the path in my text field.
If I change the If statement to:
If .Show = True Then
[Electronic File Location].Value = .InitialFileName
End If
I still have to choose a file directly but it will only store the parent directory path in the text field.
Is there a way to choose a folder and just store its path or choose a file and store its path in a text field?
Thanks for the help,
I am attempting to store a file or folder location in a text field from a dialog box. I would like the ability to choose lets say a .pdf file and store the file path in a text field or just choose a folder and store that folders file path in a text field.
Here is my code so far:
Private Sub Electronic_File_Location_DblClick(Cancel As Integer)
' Requires reference to Microsoft Office 11.0 Object Library.
Dim FileDialog As FileDialog
Dim Filelocation As String
Set FileDialog = Application.FileDialog(msoFileDialogFilePicker)
With FileDialog
.AllowMultiSelect = False
.Title = "Please select one file"
If .Show = True Then
selectedFile = FileDialog.SelectedItems(1)
[Electronic File Location].Value = selectedFile
End If
End With
End Sub
With this code I am forced to select a file directly and it will store the path in my text field.
If I change the If statement to:
If .Show = True Then
[Electronic File Location].Value = .InitialFileName
End If
I still have to choose a file directly but it will only store the parent directory path in the text field.
Is there a way to choose a folder and just store its path or choose a file and store its path in a text field?
Thanks for the help,