User select folder to export query to

B

buattis

I have a file dialog box that allows the user to select a CSV file
that they can import into an access table.

After some queries are run, I want to allow the user to select the
folder where they want to export these queries. Not the filename
though, just the folder where they want it. I was thinking of
similarly using a File Dialog box but one that selects folders not
files, and then using the folder path to export the query to. I'm not
sure how to use a file dialog box to select a folder location.

This is the code I use to allow the user to select the CSV to import.
Can i modify this code slightly to do the above?

' This requires a reference to the Microsoft Office 11.0 Object
Library.

Dim fDialog As Office.FileDialog
Dim varFile As Variant
Dim sFileName As String

' Clear the list box contents.
Me.FileList.RowSource = ""

' Set up the File dialog box.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Allow the user to make multiple selections in the dialog box.
.AllowMultiSelect = False

' Set the title of the dialog box.
.Title = "Select a File"

' Clear out the current filters, and then add your own.
.Filters.Clear
.Filters.Add "CSV Text File", "*.csv"
'.Filters.Add "All Files", "*.*"

' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then
' Loop through each file that is selected and then add it to
the list box.
For Each varFile In .SelectedItems
Me.FileList.AddItem varFile
Next
lblFileName.Caption = FileList.ItemData(0)
Else
lblFileName.Caption = ""
End If
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top