Access 2010
I am wishing to allow a user to navigate and select a file to open from within a form command button, the filedialog code below works fine but I cannot get the selected file to open! - all that happens is the file is selected and OK'd and then it all closes down.
Thanks in advance
I am wishing to allow a user to navigate and select a file to open from within a form command button, the filedialog code below works fine but I cannot get the selected file to open! - all that happens is the file is selected and OK'd and then it all closes down.
Thanks in advance
Code:
Function selectFile()
Dim fd As FileDialog, fileName As String
On Error GoTo ErrorHandler
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.AllowMultiSelect = False
If fd.Show = True Then
If fd.SelectedItems(1) <> vbNullString Then
fileName = fd.SelectedItems(1)
End If
Else
'Exit code if no file is selected
End
End If
'Return Selected FileName
selectFile = fileName
Set fd = Nothing
Exit Function
ErrorHandler:
Set fd = Nothing
MsgBox "Error " & Err & ": " & Error(Err)
End Function