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

Hi,

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?


Thanks
Karl001Asked:
Who is Participating?
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:

http://www.wiseowl.co.uk/blog/s209/type-filedialog.htm

http://www.experts-exchange.com/Database/MS_Access/Q_28066453.html

http://stackoverflow.com/questions/11743224/save-as-dialog-box-in-msaccess-vba-how

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

http://excelexperts.com/VBA-Tips-Get-A-File-Path
0
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/

Solution:
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
    Else
        'Stop Code Execution for Null File String
        End
    End If
    saveFileAs = fileName

    'Cleanup
    Set fd = Nothing
    Exit Function
 
ErrorHandler:
    Set fd = Nothing
    MsgBox "Error " & Err & ": " & Error(Err)
End Function
0

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
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.