Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 9th, 2005, 07:21 AM
Registered User
 
Join Date: Dec 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Table output to Excel and auto naming file

Hi there,

I have a table that I want to export from Access to Excel and know I can do this using either the 'Transfer to spreadsheet' or 'Output to' macros. What I want to do though is to have access automatically name the new excel file in the format tablename_date. Where the date is the date and time for running a query macro. I'd also like to set a weekly interval to run the queries automatically and output the resulting table summary file to excel file.

thanks for any assistance on how best to do :)

 
Old December 9th, 2005, 07:53 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 155
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to leehambly
Default

You will need a bit of code for this...

================================================== ==========
Public Function pfunExportTable(strTableName As String, strFilePath As String, blnFieldNames As Boolean)
Dim strFileDestination As String

If Right(strFilePath, 1) <> "\" Then strFilePath = strFilePath & "\"

strFileDestination = strFilePath & strTableName & "_" & Format(Now(), "yymmddhhss") & ".xls"

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, strTableName, strFileDestination, blnFieldNames

End Function
================================================== ==========

This should do the trick for you. Put this into its own module and then you can call it from code or from a macro.
 
Old December 9th, 2005, 10:02 AM
Registered User
 
Join Date: Dec 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the swift response. I've pasted the code into an Access module and saved it. What Macro action do I use to run the code? The 'Open Module' only opens the module without executing it. Also the table is called Summary I presume I need to replace strTableName to read strSummary?

Sorry very new to the code side of things..

thanks !

 
Old December 9th, 2005, 10:07 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 155
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to leehambly
Default

ok... the code is a function which you pass parameters to... so with a table called "Summary", to output your file with Column Headings you would use:

==============================================
pfunExportTable "Summary", "C:\Whatever", True
==============================================

The macro command you need is "RunCode"
 
Old December 9th, 2005, 10:43 AM
Registered User
 
Join Date: Dec 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think i'm almost there but get the error message 'Microsft access cant find the table pfunExportTable you entered in the expression' ??

thanks..

 
Old December 12th, 2005, 06:13 AM
Registered User
 
Join Date: Dec 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Managed to fix this, works now, Thanks Lee !!

 
Old December 13th, 2005, 06:54 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 155
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to leehambly
Default

Doh, just reading your response and noticed I seem to have used YYMMDDHHSS in the date format... you will probably want the minutes rather than the SECONDS in your filename!!! Err, what is it? YYMMDDHHNN... give that a go instead, but you may well have worked this out already.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Table path using 4 part naming convention snufse SQL Server 2000 1 February 1st, 2008 07:45 PM
How to auto link a file folder to a HTML table cJeffreywang BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 0 July 24th, 2007 02:21 PM
Fail to auto import excel to access table Ivanchan Access VBA 2 April 19th, 2007 09:34 PM
Naming a new table SKE Classic ASP Databases 2 March 23rd, 2005 03:25 PM
vb macro output file to excel mateenmohd VBScript 0 March 21st, 2005 12:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.