473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Exporting Multiple Tables from Access

Hi,

In my Access database I have a table (dbo_000_DataCubeProcessing) which contains a list of tables that I need to export to Excel on a regular basis along with a checkbox for each. Once I select the relevant table via checkbox, I have VBA code written which will pick this table and can export to a pre-defined location on my network in Excel format. I was wondering if there exists code (e.g. some type of Loop procedure) whereby I can select multiple tables via this checkbox and the VBA code can export all of these at once?

This would be very useful as there are occasions where I to export 10-15 tables at the same time and would like to perform it in one VBA procedure instead of re-running each time

My current code is:
Expand|Select|Wrap|Line Numbers
  1. Sub ExportTable()
  2.  
  3. 'Define Variables
  4. SelectTableToExport = DLookup("[Table]", "dbo_000_DataCubeProcessing", "[Select] = True")
  5. TableSaveName = DLookup("[ExportFileName]", "dbo_000_DataCubeProcessing", "[Select] = True")
  6.  
  7. 'Export file to network
  8. DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, SelectTableToExport, "H:\" & TableSaveName, True
  9.  
  10. 'Reset Table
  11. DoCmd.SetWarnings False
  12. DoCmd.RunSQL "UPDATE Dbo_000_DataCubeProcessing SET [Select]=No"
  13. DoCmd.SetWarnings True
  14.  
  15. End Sub
Thanks!
Dan
Jan 2 '08 #1
2 4529
FishVal
2,653 Expert 2GB
Hi, Dan.

I think you may try to run VBA export procedure in update query thus invoking it for each record. Anyway you already run an update query at the end of the export sequence. ;) Additionally this VBA function may return boolean value to update [Select] field (False of success, True if export failed).

Expand|Select|Wrap|Line Numbers
  1. Public Function ExportTable2Excel(strTableName As String, _
  2.                                   strFileNameToExportTo As String) As Boolean
  3.  
  4.     On Error GoTo ExportFailed
  5.     DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
  6.         strTableName, "H:\" & strFileNameToExportTo, True
  7.     ExportTable2Excel = False
  8.  
  9. ExitFunc:
  10.     Exit Function
  11.  
  12. ExportFailed:
  13.     ExportTable2Excel = True
  14.     Resume ExitFunc
  15.  
  16. End Function
  17.  
Then run update query:
Expand|Select|Wrap|Line Numbers
  1. UPDATE Dbo_000_DataCubeProcessing SET [Select]=ExportTable2Excel([Table], [ExportFileName]) WHERE [Select]=True;
  2.  
Regards,
Fish

P.S. Make backup first. LOL.
Jan 2 '08 #2
NeoPa
32,556 Expert Mod 16PB
That's an ingenious approach Fish :)
Just as an alternative (better or worse often depends on the OP's preferences) I would suggest using a DAO RecordSet (Basic DAO recordset loop using two recordsets) approach.
The RecordSet would be the SQL that selects just the records required (WHERE ([SELECT])).
Each iteration through the loop would include an "export" as well as a couple of lines to reset the [SELECT] field (using .Edit & .Update).
Jan 3 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works...
4
by: Dom Hicklin | last post by:
I have created a form onto which images can be dropped and thus added to the OLE field of a Table (Access 2000 linked to SQL 2000 server). I use the Stephen Lebans ExportOLE function to do this...
3
by: premmehrotra | last post by:
I am using Access 2000 and Oracle 9.2.0.x on a Windows 2000. I have setup Oracle 9.2 ODBC Driver (I have not yet figured how to set Microsoft's Oracle ODBC driver). I am exporting a table from...
5
by: mik18 | last post by:
I'm having trouble with exporting reports to Word in the rtf format and I'm hoping someone has a solution. The reports are losing their formats. Not all the formating is lost but some is and of...
2
by: Regnab | last post by:
I've got my code working so that it'll count the number of columns in the table and move across (eg Range A-P and then range Q-W). Problem is when I get to the end of the single letters and get...
8
by: chippy | last post by:
Hi, I've a VB script that creates a Access object in a word doc. Here is the full script. It works for all but the Export. Which always fails with a 3011 error. If I do the same in Access as a...
0
by: Mike Collins | last post by:
I am trying to export data from multiple tables in SQL Server to an XML file so I can then import it to another database. It seems to be working fine for exporting, but I am having trouble...
1
by: John Overton | last post by:
I have a new requirement to Import and Export Excel tables into and out of Access 2003. The Excel tables are located on a remote server but I know the path to the Excel Files. Can you please help...
2
by: jjwiet | last post by:
Hello, I use access 2003 and attempting to export/copy records between two access databases (almost identical) with multiple tables (both databases having the same relations between the tables)....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.