Solved

Capture Full Path from MS File Picker

Posted on 2014-02-02
7
522 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
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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

770 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