getting a file name from a dialog file picker



I have a button on my form and I'm looking for the best way to launch the
file picker, then pass that selection to a textbox on the form called
I can't find any code that works yet, so I need some advice or help.

Any ideas?
Dec 2, 2016
Reaction score
This sub opens a file picker, and will return the full UNC path when searching a network share, otherwise it'll return the mapped drive path. It then saves the path for the chosen file to a clickable hyperlink text box on a MS Access continuous subform. It's called from a command button next to the hypFilePath textbox on the subform.
Short and sweet, and works like a charm!:nod:

Private Sub cmdPickFile_Click()
'Author: Dave Rowland
'Date added: 12/2/2016
Const msoFileDialogFilePicker As Long = 3
Dim objDialog As Object, strPath As String, strFileName As String

Set objDialog = Application.FileDialog(msoFileDialogFilePicker)
With objDialog
.Title = "Please select a file for this account"
.AllowMultiSelect = False
If .SelectedItems.Count = 0 Then
MsgBox "No file selected."
strPath = .InitialFileName
strFileName = Dir(.SelectedItems(1))
Me.hypFilePath.Value = strFileName & "#" & strPath & strFileName
End If
End With
End Sub

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question