Solved

Extract folder selected from msoFiledialogFilePicker

Posted on 2011-03-24
5
730 Views
Last Modified: 2013-11-27
What I am trying to do is see what folder the user selects using the FileDialogPicker. I then want to store that value in a table so the next time they open the DB it 'remembers' the last location that they selected. I know if you remove the .InitialFileName it remembers that location per session, but I want to store it so that the next time they open the DB it goes right back to where they were.

Do I need to use a msoFileDialogFolderPicker in conjuction with this? Thanks for any tips.

 
Dim strSelectedFile As String
    
    Set fdg = Application.FileDialog(msoFileDialogFilePicker)
'    fdg.InitialFileName = "c:\"
    
    With fdg
        .Filters.Clear
        .Filters.Add "Excel Files", "*.xls"
        .Filters.Add "Excel 2007", "*.xlsx"
'        .AllowMultiSelect = True
        .InitialView = msoFileDialogViewDetails
       
        If .Show = -1 Then
            DoCmd.SetWarnings False
            DoCmd.RunSQL ("Delete * from DynamicReportTest")
            For Each vrtSelectedItem In .SelectedItems
            strSelectedFile = vrtSelectedItem
            MsgBox strSelectedFile
            DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "DynamicReportTest", strSelectedFile, False, , False
            
          
        
        Next vrtSelectedItem
Else
MsgBox "No File Selected"
End If
End With

Open in new window

0
Comment
Question by:G Scott
  • 3
  • 2
5 Comments
 
LVL 1

Author Comment

by:G Scott
ID: 35205514
Just thought of a solution, but still need help. If I take the whole selected file name and trim off the actual file name from the last "\" it would work. But I am not sure how to do that either. You can see in my code above  in line 18 that I am throwing up the whole file name/location to a msgbox, I can jus change that to a msgbox Trim(what do I put in here) kind of thing.  Right?
0
 
LVL 19

Accepted Solution

by:
darbid73 earned 500 total points
ID: 35205903
.SelectedItems is going to give you a path.  You need to do something like this

Some people take the path as a string and will find the "/" in it.

I use the filesystemobject instead see MSDN reference and example

You will need to add a reference to the file system object
Dim filesystem As New FileSystemObject

StripFilename = filesystem.GetParentFolderName(sPathFile) & "\"

Open in new window

0
 
LVL 1

Author Comment

by:G Scott
ID: 35206252
Hey darbid,

According to this post you can no longer assign FileSystemObjects in Access 2007:

http://www.experts-exchange.com/Microsoft/Development/MS_Access/Access_Coding-Macros/Q_23589830.html

Am I looking at the right thing?
0
 
LVL 19

Expert Comment

by:darbid73
ID: 35206352
I think a fix is the solution to that

Source

Hotfix
0
 
LVL 1

Author Closing Comment

by:G Scott
ID: 35207179
Sorry darbid, your solution worked without the hotfix. I was looking for a FileSystemObject reference and not the MS Scripting reference.

Thanks for the help!
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

744 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

11 Experts available now in Live!

Get 1:1 Help Now