Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want Query to Open an Excel Spreadsheet

Status
Not open for further replies.

gaRed

MIS
Jun 17, 2002
18
US
What is the best way to have the results of a query automatically open up in an excel spreadsheet? Thanx.
 
Hi,
This code will do it for you.
Design a new module (or manipulate this with Private Subs instead of Functions and place in your form) and copy/paste this into it. Change qryTestPlease to your query or table that you are trying to export. And change C:\Testplease.xls to your spreadsheet that you export to and that you want to open.

Function SpreadSheet()
Dim gsSpreadSheet As String
Dim successful

DoCmd.TransferSpreadsheet acExport, 8, "qryTestPlease", "C:\testplease.xls", True, ""


gsSpreadSheet = "C:\testplease.xls"
successful = Shell("C:\Program Files\Microsoft Office\Office\excel.exe " & _
Chr$(34) & gsSpreadSheet & Chr(34), vbMaximizedFocus)

End Function

Save it as mdlSpreadSheet (or whatever)... Now just call the function whenever you want it to run.

-Josh ------------------
-JPeters
Got a helpful tip for Access Users? Check out and contribute to 'How to Keep Your Databases from becoming Overwhelming!'
thread181-293590
jpeters@guidemail.com
------------------
 
Do I put this code in the form that the user uses to run the report? Or should I make a report, put the code there, and have it create the spreadsheet? I really want to skip the report and go from the form straight to the spreadsheet.
Thanx
 
Hey,
There's no report that opens up with this code. Just a spreadsheet. You'll notice that you have to edit the code to change the paths so they match your comp's specs. Ie: rename the Xls paths, etc.

You can either make a module and copy/paste that in there with the Function heading. Or you can create a button, and put the code behind the button (but you don't want to copy.paste the Function () and End Function ... Access should create Private Sub () and End Sub). IF you need any more help, just post.

-Josh ------------------
-JPeters
Got a helpful tip for Access Users? Check out and contribute to 'How to Keep Your Databases from becoming Overwhelming!'
thread181-293590
jpeters@guidemail.com
------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top