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
323 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 119

Accepted Solution

by:
Rey Obrero 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 Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 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

23 Experts available now in Live!

Get 1:1 Help Now