Solved

Get path and filename with VBA

Posted on 2013-10-29
3
1,830 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

821 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