Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Capture Full Path from MS File Picker

Posted on 2014-02-02
7
Medium Priority
?
531 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

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 500 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 500 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

879 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