Jelle van der Heijden
Jelle van der Heijden

Reputation: 47

Access VBA Forms filepath via filepicker

I got this code for my Access Form to open the filepicker and select a file. I found the code on the internet.

How can I make it so that I get the filepath aswel? Now I only get the filename..

Private Sub FilePath_Click()
Const msoFileDialogFilePicker As Long = 3
Dim objDialog As Object

Set objDialog = Application.FileDialog(msoFileDialogFilePicker)

With objDialog
.AllowMultiSelect = False
.Show
If .SelectedItems.Count = 0 Then
    MsgBox "Er is geen bestand gekozen."
Else
    Me.FilePathForm.Value = Dir(.SelectedItems(1), sPath)
End If
End With
End Sub

Upvotes: 0

Views: 50

Answers (1)

Applecore
Applecore

Reputation: 4099

The value returned by the FileDialog contains the full path and name of the file selected - by using Dir you are just getting the file name. In order to get the folder, you can use this:

        Me!FilePathForm = Dir(.SelectedItems(1), sPath)
        Me!FolderName= Left(.SelectedItems(1), InStrRev(.SelectedItems(1), "\"))

Regards,

Upvotes: 1

Related Questions