Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 9th, 2005, 07:21 AM
Registered User
 
Join Date: Dec 2005
Location: , , .
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 :)

Reply With Quote
  #2 (permalink)  
Old December 9th, 2005, 07:53 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Salisbury, Wiltshire, United Kingdom.
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.
Reply With Quote
  #3 (permalink)  
Old December 9th, 2005, 10:02 AM
Registered User
 
Join Date: Dec 2005
Location: , , .
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 !

Reply With Quote
  #4 (permalink)  
Old December 9th, 2005, 10:07 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Salisbury, Wiltshire, United Kingdom.
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"
Reply With Quote
  #5 (permalink)  
Old December 9th, 2005, 10:43 AM
Registered User
 
Join Date: Dec 2005
Location: , , .
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..

Reply With Quote
  #6 (permalink)  
Old December 12th, 2005, 06:13 AM
Registered User
 
Join Date: Dec 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #7 (permalink)  
Old December 13th, 2005, 06:54 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Salisbury, Wiltshire, United Kingdom.
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


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



All times are GMT -4. The time now is 06:34 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.