Solved

Capture Full Path from MS File Picker

Posted on 2014-02-02
7
520 Views
Last Modified: 2014-02-03
Hi Experts,
I am using the File Picker in my MS Access Application and would like to be able to capture the Full Path for the File 'Picked' so that I can put it in a table and retrieve it to return to I later via the InitFileName below..

Here is the code I use to pick the file.
Private Sub CmdF10090_820_Click()
On Error GoTo Err_CmdF10090_820_Click
Dim InitFileName As Variant
InitFileName = "M:\"
Dim IngCount As Long
Dim fd As FileDialog
Dim FileNameArray As Variant
Dim Filename   As Variant
ReDim FileNameArray(0)
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
    '.InitialFileName = InitFileName
    .InitialView = msoFileDialogViewList
    .AllowMultiSelect = False
    .Filters.Clear
       If .Show = -1 Then
          For Each Filename In .SelectedItems
              FileNameArray(UBound(FileNameArray)) = Filename
              ReDim Preserve FileNameArray(UBound(FileNameArray) + 1)
          Next Filename
       End If
    End With
    If Not IsEmpty(FileNameArray(0)) Then
        ReDim Preserve FileNameArray(UBound(FileNameArray) - 1)
    Else
         FileNameArray(0) = ""
    End If
PARM_EXPORT_FOLDER_FILE = CStr(FileNameArray(0))
Exit_CmdF10090_820_Click:
    Exit Sub
Err_CmdF10090_820_Click:
    'MsgBox Err.DESCRIPTION
    Resume Exit_CmdF10090_820_Click
End Sub

Thanks.  Bob Collison
0
Comment
Question by:Bob_Collison
  • 3
  • 2
  • 2
7 Comments
 
LVL 10

Expert Comment

by:Gozreh
Comment Utility
Whats your question ? Please explain more

the " CStr(FileNameArray(0)) " should give you the full path of the file you selected
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
you use this setting

  .AllowMultiSelect = False

which means that you can only choose a single file, you don't need an array to retrieve the file selected

   If .Show = -1 Then
        filename= .SelectedItems(1)
   end if
0
 

Author Comment

by:Bob_Collison
Comment Utility
Hi Gozreh,

I want to modify this code to not only display the FileNames from which to pick a particular File to be used for other things but to capture the Full Path at which the Filenames reside so that I can store it in a table and retrieve it at some other time to use as the value for the .InitialFileName parameter to go back to the same location.

I don't understand your reference to " CStr(FileNameArray(0)) " as I don't know what this is.  If it somehow contains what I am looking for how do I use it and where in the code I supplied would it reside?

Thanks.  Bob Collison.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Bob_Collison
Comment Utility
Hi  Rey,

If I understand you are suggesting only displaying one file but I need to display all that are in the Path.

I don't see how this will provide the Path..
Thanks.  Bob Collison.
0
 
LVL 10

Assisted Solution

by:Gozreh
Gozreh earned 125 total points
Comment Utility
I change around the code for you
Private Sub CmdF10090_820_Click()
   On Error GoTo Err_CmdF10090_820_Click
   Dim InitFileName As Variant
   InitFileName = "M:\"
   
   Dim fd As FileDialog   
   Dim FullFilePath As String
   
   Set fd = Application.FileDialog(msoFileDialogFilePicker)
   With fd
      .InitialFileName = InitFileName
      .InitialView = msoFileDialogViewList
      .AllowMultiSelect = False
      .Filters.Clear
      If .Show = True Then
         FullFilePath = .SelectedItems(1)
         MsgBox FullFilePath
      Else
         MsgBox "File not selected !"
      End If
   End With
   
Exit_CmdF10090_820_Click:
    Exit Sub
Err_CmdF10090_820_Click:
    MsgBox Err.Description
    Resume Exit_CmdF10090_820_Click
End Sub

Open in new window

0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 125 total points
Comment Utility
assuming you selected a file "M:\folder1\folder2\myFile.txt"
the path will be

dim path as string
  If .Show = -1 Then
        filename= .SelectedItems(1)
        path=left(filename, instrrev(filename,"\"))
   end if


path="M:\folder1\folder2\"

is that what you are looking for?
0
 

Author Comment

by:Bob_Collison
Comment Utility
Hi Experts,
Both of these together do what I was looking for so I will split the points.
Thank you both.
Bob Collison.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This is a little timesaver I have been using for setting up Microsoft Small Business Server (SBS) in the simplest possible way. It may not be appropriate for every customer. However, when you get a situation where the person who owns the server is i…
The password reset disk is often mentioned as the best solution to deal with the lost Windows password problem. In Windows 2008, 7, Vista and XP, a password reset disk can be easily created. But besides Windows 7/Vista/XP, Windows Server 2008 and ot…
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…
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…

763 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

6 Experts available now in Live!

Get 1:1 Help Now