I have five queries that I would like to export into one Excel document
(have each query be a separate tab). Is there a way to write code for a
command button that will automatically export these queries to Excel?
Thank you in advance for any assistance.
LB
John Vinson - 31 Mar 2005 18:30 GMT
>I have five queries that I would like to export into one Excel document
>(have each query be a separate tab). Is there a way to write code for a
[quoted text clipped - 3 lines]
>
>LB
Yes. See the VBA help for the TransferSpreadsheet method. You can
specify Excel ranges in the method's operands.
John W. Vinson[MVP]
Charles - 31 Mar 2005 19:07 GMT
Hi I have always found it is easier to create a csv file
on the desktop use the following -
Add this code to the button or trigger you want. For it
to work you have to make a query called querynamehere or
rename to whatever you like.
hope that helps
Charles
Dim path As String
Dim wShell As Object
Dim strSql As String
Set wShell = CreateObject("WScript.Shell")
path = wShell.SpecialFolders("Desktop")
path2 = CurrentProject.path
Set wShell = Nothing
DoCmd.TransferText acExportDelim, , "qrynamehere", path
+ "\export" & Format(Now(), "ddmmyyyy") & ".csv", True
MsgBox ("You will now find a file on the desktop if you
left the code as you found it in the above. If add a 2
to the end of the word "path" the file will be placed in
the databases root directory"), vbInformation, "Msgbox
title here"