Solved

Get path and filename with VBA

Posted on 2013-10-29
3
1,721 Views
Last Modified: 2013-10-29
Thank you very much for your help.

I need to import a csv file into a table. I would like the use VBA to open a dialog box where the user can point to the selected file to import. The code below opens a dialog box and allows the user to select a file and it puts the file name in the text box. But it doesn't include the full path. I need the full path for my next section of code to import the file.

How can I get the path with the file name?  


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

Thanks
Bob
0
Comment
Question by:Rwardlow
3 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39609986
The Dir() function limits the output to just the filename.

For the full path, simply drop the dir():

Me.FileNameTextBox = .SelectedItems(1)

Open in new window

0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39609991
add another textbox for full path


Me.FilePathTextbox = .SelectedItems(1)
0
 
LVL 1

Author Closing Comment

by:Rwardlow
ID: 39610030
Excellent, thank you very much.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now