Solved

Send query result to a user's computer as an Excel file but allow them to select the location and name the file

Posted on 2014-01-24
2
333 Views
Last Modified: 2014-01-29
I want to, with a command button on a form, send a query result to a user's computer as an Excel file but allow them to select the location it is to go to on their computer and name the file.

How can I do this?  Right now I have:

DoCmd.TransferSpreadsheet acExport, 10, "qryShipments", Environ("userprofile") & "\Desktop\Inventory.xlsx", True

But that sends it to their desktop by default and replaces the file that was there already if there was one.
0
Comment
Question by:SteveL13
2 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39807959
first,   place this function in a regular module
Function SaveExcelFileAs()
Dim fd As Object, strLocation As String
strLocation = Environ("UserProfile") & "\Desktop\"
Set fd = Application.FileDialog(2)
With fd
    .Title = "Save File As"
    .ButtonName = "Save As"
    .InitialFileName = strLocation & "Inventory.xlsx"
    If .Show Then
        SaveExcelFileAs = .SelectedItems(1)
    End If
End With
End Function

Open in new window


change the codes in the command button to this

Dim strFileName As String
strFileName = SaveExcelFileAs()

If strFileName & "" <> "" Then
    DoCmd.TransferSpreadsheet acExport, 10, "qryShipments", strFileName, True
End If

Open in new window

0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 39810773
How are you going to send the file to the other user's computer?  By email, or what?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

820 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