Jim
Jim

Reputation: 11

How to insert entire file path into text box, not just filename? Access 2010

I am currently using the following code to select a file and add its path to a text box.

 Dim objDialog As Object

 Set objDialog = Application.FileDialog(3)

 With objDialog
   .AllowMultiSelect = False
   .Show
   If .SelectedItems.Count = 0 Then
     MsgBox "No file selected."
   Else
     Me.FileNameTextBox = Dir(.SelectedItems(1))
   End If
 End With
 Set objDialog = Nothing

How do I make it so the entire file path is inserted, not just the file name?

Upvotes: 1

Views: 4119

Answers (2)

Adam Marsden
Adam Marsden

Reputation: 1

you need to remove the dir() part, EG....

Me.FileNameTextBox = .SelectedItems(1)

Upvotes: 0

fthiella
fthiella

Reputation: 49049

.SelectedItems(n) already contains the full path and filename. If what you need is just to separate the name of the file from its path, instead of using the Dir function you could use something like this:

Me.FileNameTextBox = Mid$(.SelectedItems(1), InStrRev(.SelectedItems(1), "\") + 1)
Me.PathTextBox = Left$(.SelectedItems(1), InStrRev(.SelectedItems(1), "\"))

Hope this helps!

Upvotes: 1

Related Questions