exporting codes

  • Thread starter Thread starter Lauren B
  • Start date Start date
L

Lauren B

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

Yes. See the VBA help for the TransferSpreadsheet method. You can
specify Excel ranges in the method's operands.

John W. Vinson[MVP]
 
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"
 
Back
Top