Export Access data to Excel (2010) Let user choose save destination?


Here the code I use to transfert data from an Access query to an Excel file.

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qry_Transfert_XL_Client", _
"S:\Client\Test.xlsx", True

Instead of specified the destination, ""S:\Client\Test.xlsx"", How can we let the user choose the destination?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carol ChisholmCommented:
You need to allow the user to browse the file system:
It is a bit different depending on the versions:




You can also get the path and then construct the variable for the filename in your code

Karl001Author Commented:
Thanks Carol for the information. You gave me the right direction

The solution was completed with the information found at: : http://www.ntechcomm.com/2014/04/file-dialog-save-as-access-vba/

1st -  To have FileDialog object
Atl F11, Tools, References, Microsoft Office 14.0 Object Library    
Microsoft Office 14.0 Object Library is for Microsoft Access 2010

2nd - Code
Private Sub btnTransfertToExcel_Click()
     DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml,    
    “qry_Transfert_XL_Client",   saveFileAs, True
End sub

Where “saveFileAs”  is a function:

April 23, 2014 by Ryan McCormick
Public Function saveFileAs() As String
    Dim fd As FileDialog, fileName As String

    On Error GoTo ErrorHandler

    Set fd = Application.FileDialog(msoFileDialogSaveAs)
    If fd.Show = True Then
        If fd.SelectedItems(1) <> vbNullString Then
            fileName = fd.SelectedItems(1)
        End If
        'Stop Code Execution for Null File String
    End If
    saveFileAs = fileName

    Set fd = Nothing
    Exit Function
    Set fd = Nothing
    MsgBox "Error " & Err & ": " & Error(Err)
End Function

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Karl001Author Commented:
A complete solution
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.