473,382 Members | 1,332 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,382 software developers and data experts.

export each record into separate excel file

4
I am trying to export each record in an Access database into its own separate Excel file. Is there an easy way to do this? Please dumb it down for me as much as possible. Thank you.

Also is this possible using a macro?
Oct 16 '06 #1
2 3371
PEB
1,418 Expert 1GB
Hi,

It's possible using Excel Automation in Vb...

See some of the last threaDS in thescripts.com in the Access forum ther is a lot information about Connecting to Excel

search about

CreateObject

Excel

Best regards
Oct 21 '06 #2
MMcCarthy
14,534 Expert Mod 8TB
You would need a function built in vba in a module in the database. This is the simplest solution I can think of:

Create a second table with the fields from the table or query you need to output.

Then put the following code in any module. Please check this code for the instructions on the changes you need to make.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Function outputRecords()
  3. Dim db As DAO.Database
  4. Dim rs1 As DAO.Recordset
  5. Dim rs2 As DAO.Recordset
  6. Dim path As String
  7. Dim i As Integer
  8.     Set db = CurrentDb
  9.     Set rs1 = db.OpenRecordset("TableOrQueryName") ' replace with your table or query name
  10.     Set rs2 = db.OpenRecordset("NewTableName") ' replace with new table name
  11.  
  12.     ' Replace the path with whichever folder you want to put the spreadsheets in
  13.     path = "C:\"
  14.  
  15.     rs1.MoveFirst
  16.     Do Until rs1.EOF
  17.         rs2.AddNew
  18.         For i = 1 To 20 ' replace 20 with the number of fields in your table or query
  19.             rs2.Fields(i) = rs1.Fields(i)
  20.         Next i
  21.         rs2.Update
  22.         DoCmd.OutputTo acOutputTable, "NewTableName", FormatXLS, path & "RecordNo" & i & ".xls"
  23.         DoCmd.RunSQL "DELETE * FROM NewTableName;"
  24.         rs1.MoveNext
  25.     Loop
  26.  
  27.     rs1.Close
  28.     rs2.Close
  29.     Set rs1 = Nothing
  30.     Set rs2 = Nothing
  31.     Set db = Nothing
  32.  
  33. End Function
  34.  
  35.  
open a macro and select the Run Code option. Then put in the function name as below.

outputRecords ()
Oct 23 '06 #3

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

Similar topics

0
by: Bryan Russell | last post by:
Hi, My asp/sql server application gets an error, but only when you use the Excel export option: <% Response.ContentType="application/vnd.ms-excel" %> (very popular w/ users) I think...
1
by: Matt | last post by:
I have an ASP page that calls ASP routines that I created that execute a database query and return the results to a recordset. I then iterate through the recordset and display the data in a table....
6
by: Robin Cushman | last post by:
Hi all, I need some help -- I'm working with an A2K database, using DAO, and am trying to read records into a Crystal Report and then export it to a folder on our network as an Excel...
4
by: paul.chae | last post by:
I have a table in Access with about 3000 records. There are ~60 unique values in the ID field for the 3000 records. What I would like to do is automatically generate multiple Excel worksheets...
6
by: jcf378 | last post by:
hello-- i am having trouble figuring out how to export individual records from an Access 2002 Form into a pre-existing Excel spreadsheet, such that the exported record is merely appended to the...
3
by: =?Utf-8?B?bWFuaWthMDI=?= | last post by:
Hi, I have a GridView control in page called eventslisting which is inheriting from a MasterPage. The normal code to export to GridView does not work and gives me an error - "Control of type...
2
by: arnabit | last post by:
Hi everyone, I am facing a problem in exporting CSV file.I able to export it properly in IE7 bbut in Mozila it seems the file name is changed and an extra , is added in the file name.say if the...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
3
by: jmarcrum | last post by:
I want to export a report (that contains two separate queries, 1. Current year data, and 2. split-year data) from access into excel, but everytime I run my code and export the data to excel, it looks...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.