Solved

Capture Full Path from MS File Picker

Posted on 2014-02-02
7
526 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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.
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…
Suggested Courses

623 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