Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > Changing tablename in docmd.Transferspreadsheet in access VBA


Reply
 
Thread Tools Display Modes
  #1  
Old 06-12-2012, 07:25 AM
singhg8 singhg8 is offline
Newcomer
 
Join Date: Dec 2011
Posts: 7
Default Changing tablename in docmd.Transferspreadsheet in access VBA


Hi All,


Process: I have the below code which gets the base SQL statement and defines the working query. Based on this it then generates & exports Excel spreadsheet into a defined folder (wkfolder).

Objective: The exported workbook name is fine but the sheet-name comes up as "RunReport". I wish to change the sheetname to "UpdateData". Is this possible please?


QryDef = CurrentDb.QueryDefs("MyQuery").SQL

CurrentDb.QueryDefs("RunReport").SQL = QryDef

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "RunReport", wkFolder & "1002 Update 01_First Letter.xls"
Reply With Quote
  #2  
Old 06-12-2012, 11:48 PM
singhg8 singhg8 is offline
Newcomer
 
Join Date: Dec 2011
Posts: 7
Default

Is there anyone who can help with my query please? It is quite urgent!!!
Reply With Quote
  #3  
Old 06-13-2012, 01:59 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,885
Default

Seems that the sheetname is the same as the table or query name.
Most easy seems to change the table/query name.

Otherwise you have to use Excel automation to open the created Excel file and change the name of the worksheet.
Reply With Quote
  #4  
Old 06-13-2012, 02:13 AM
singhg8 singhg8 is offline
Newcomer
 
Join Date: Dec 2011
Posts: 7
Default

I have tried changing the query name in the below statement but it doesn't seem to work. The file will be generated automatically every week.

CurrentDb.QueryDefs("RunReport").SQL = QryDef

I am new to VBA and learning the code language. Can you please elaborate how can we exactly use excel automation from the access vba itself?
Reply With Quote
  #5  
Old 06-13-2012, 02:57 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,885
Default

Reply With Quote
  #6  
Old 06-14-2012, 07:05 AM
singhg8 singhg8 is offline
Newcomer
 
Join Date: Dec 2011
Posts: 7
Default

Thanks Flyguy. I will try
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->