LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.access.formscoding
external usenet poster
 
Posts: 1
Default Output an Access Table or Query to Excel

I thought I would post this subroutine for outputting tables or queries
to Excel. My thanks for Jamie Collins for his response to a 2005 post.
He showed an easy way to do this without having to use Excel objects.
The instructions point out why this is an alternative to the docmd
method.

'---------------------------------------------------------------------------------------
' Procedure : subDumpToExcel
' DateTime : 11/22/2006 11:03
' Author : ws
' Copyright: Public Domain
' Purpose : This subroutine will export a table or query to Excel
' This offers more control than is possible with the
DoCmd.OutputTo method
' DoCmd.OutputTo creates a new Excel file for each output
(or overwrites an existing file)
' This option will add a new worksheet for the data
output, if a worksheet with the name does not exist
' Inputs : Call the routine as subDumpToExcel [Query or Table to
Output], [Output Path and File Name], [Worksheet Name]
'---------------------------------------------------------------------------------------
'
Sub subDumpToExcel(strItemToOutput As String, strOutputPathAndFile As
String, strWorksheetName As String)

Dim strSQLToExecute As String

'On Error GoTo subDumpToExcel_Error

strSQLToExecute = "SELECT [" & strItemToOutput & "].* INTO [Excel
8.0;Database=" & strOutputPathAndFile & "].[" & strItemToOutput & "]
FROM " & strItemToOutput
Debug.Print "strSQLToExecute is " & strSQLToExecute
CurrentDb.Execute strSQLToExecute

On Error GoTo 0
Exit Sub

subDumpToExcel_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in the
subDumpToExcel subroutine"

End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection of Excel 07 pivot table to Access Query makes DB read o Chuck W[_2_] Excel Discussion (Misc queries) 0 October 9th 09 03:45 PM
Excel Pivot Table or Access Cross Tab Query Question greene2j Excel Discussion (Misc queries) 0 January 14th 08 01:49 AM
VBA - query an Access table - results in Excel rirus Excel Programming 3 August 21st 06 07:29 PM
Linking parameter query from Access to pivot table in Excel ken1975 Excel Discussion (Misc queries) 2 June 20th 06 01:51 PM
Linking a table in Access to a table in Excel using MS Query Diana[_5_] Excel Programming 1 January 16th 04 09:43 PM


All times are GMT +1. The time now is 05:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"