Solved

Capture Full Path from MS File Picker

Posted on 2014-02-02
7
524 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 10

Expert Comment

by:Gozreh
ID: 39828463
Whats your question ? Please explain more

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

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39828756
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
ID: 39830754
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:Bob_Collison
ID: 39830768
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
ID: 39830818
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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 125 total points
ID: 39830823
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
ID: 39830919
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

732 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