Solved

MS Access 2013:  Export Multiple Access Tables to Same Excel Spreadsheet (Multiple Sheets)

Posted on 2013-12-22
7
3,851 Views
Last Modified: 2013-12-24
MS Access 2013:  I have a database with 6 tables.  It would be very useful to me if I could get a code that, upon the click of a Control Button (Command15), would automatically export each of these tables to an MS Excel Spreadsheet (each Table is placed into a separate sheet).  Attached is my Database and the 6 tables I would like exported are:

InputT1
InputT2
SentenceOptionT1
SentenceOptionT2
NotesT1
NotesT2

The Excel Spreadsheet (Path) is:  
C:\Users\Matt\Desktop\Access Table Dump.xlsx

Can anyone help with this one?
Big-Test.accdb
0
Comment
Question by:mdstalla
  • 3
  • 2
  • 2
7 Comments
 
LVL 30

Accepted Solution

by:
hnasr earned 500 total points
ID: 39735243
Try: This command for Office 2013.

Excel file: D:\xl.xlsx
Use sheet names not present in workbook.

CurrentDb.Execute "SELECT * INTO [Excel 12.0;DATABASE=" _
    & "D:\xl.xlsx" & "].[" & "InputT1" & "] FROM [" & "InputT1" & "]"

Repeat for other tables.

Access reported error when appending.

Check database.
Big-Test-1.accdb
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39735415
using a click event of a button

private sub cdmExport_click()

docmd.transferspreadsheet acexport,10, "InputT1", "C:\Users\Matt\Desktop\Access Table Dump.xlsx", True, "InputT1"

docmd.transferspreadsheet acexport,10, "InputT2", "C:\Users\Matt\Desktop\Access Table Dump.xlsx", True, "InputT2"

docmd.transferspreadsheet acexport,10, "SentenceOptionT1", "C:\Users\Matt\Desktop\Access Table Dump.xlsx", True, "SentenceOptionT1"

docmd.transferspreadsheet acexport,10, "SentenceOptionT2", "C:\Users\Matt\Desktop\Access Table Dump.xlsx", True, "SentenceOptionT2"

docmd.transferspreadsheet acexport,10, "NotesT1", "C:\Users\Matt\Desktop\Access Table Dump.xlsx", True, "NotesT1"

docmd.transferspreadsheet acexport,10, "NotesT2", "C:\Users\Matt\Desktop\Access Table Dump.xlsx", True, "NotesT2"


end sub
0
 

Author Comment

by:mdstalla
ID: 39737223
Capricorn1.  Your codes did not work.

Hnasr:  You codes worked-- however, I would like it if every time Access Exports data to that Spreadsheet, it replaces any/all data that my already exist (say, from a previous export).

Could you take a look at it and adjust your coding?  You are the MAN!
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39737299
@ mdstalla

what did not work ? what is the problem?
0
 
LVL 30

Expert Comment

by:hnasr
ID: 39737332
Try this version:
Added code to delete previous sheets.
Big-Test-2.accdb
0
 

Author Comment

by:mdstalla
ID: 39737335
I don't know... I plugged them in, hit the Control Button, opened the Spreadsheet and; Nada!

Regardless, it ends up that there's some refining to do with the ultimate function I had in mind.  If you've got time and are willing to put up with me; let me ask you this question (related):

I'd still like to do what you were helping me out with before… only, the sheets within Excel cannot be brand new every time.  My spreadsheet (and its sheets) are already made, and any Access exports to them should only re-write data, not create entirely new spreadsheets.

Now here's the real kicker:  Upon exporting from Access to Excel, I would like the layout of Column’s and Rows to be reversed.  Example:  Records exported from Access that would normally be displayed as Column’s:  'A, B, C and D etc.' should show up as Rows in Excel: 1, 2, 3 and 4, etc.
Buddy, if you can give me direction on how to do this; I will give you accolades for the next 3 weeks straight!  Shit, I’ll Western Union you $50!

Thanks.
0
 
LVL 30

Expert Comment

by:hnasr
ID: 39737490
For the new requirement, you need to start a new question.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now