473,465 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Access Table Export to specific excel row

Nathan H
104 New Member
I am curious if this is possible to do. I have a case scenario where I need to export data from an access table into an excel spreadsheet, and have that data start on row 5. Can't do it from Excel with a query, as the machine has Access 2007 runtime db and Excel 2003 (which does not recognize the new access extension).

Thanks

Nathan
Dec 13 '07 #1
10 6966
ADezii
8,834 Recognized Expert Expert
I am curious if this is possible to do. I have a case scenario where I need to export data from an access table into an excel spreadsheet, and have that data start on row 5. Can't do it from Excel with a query, as the machine has Access 2007 runtime db and Excel 2003 (which does not recognize the new access extension).

Thanks

Nathan
I did it from Excel, but I totally forgot about it recognizing the new 2007 extension. It could be done within Access by using Automation code with similarities to what I am showing below, but it would be more complex.
Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandButton1_Click()
  2. Dim MyDB As DAO.Database, MyRS As DAO.Recordset
  3. Dim wk As Workspace, intCols As Integer, intRow As Integer
  4.  
  5. ' Create Microsoft Jet Workspace object.
  6. Set wk = CreateWorkspace("", "admin", "", dbUseJet)
  7.  
  8. ' Open Database object from saved Microsoft Jet database for exclusive use.
  9. Set MyDB = wk.OpenDatabase("C:\Test\Test.mdb", True)
  10.  
  11. ' Open Recordset based on the Employees Table
  12. Set MyRS = MyDB.OpenRecordset("qryEmployees", dbOpenSnapshot)
  13.  
  14. 'Field Names on Row 5 - then make Bold
  15. For intCols = 0 To MyRS.Fields.Count - 1
  16.   Cells(5, intCols + 1).Value = MyRS.Fields(intCols).Name
  17. Next
  18. Range("A5:Z5").Select: Selection.Font.Bold = True
  19.  
  20. 'Bring the data in starting from Row 6
  21. Worksheets("Sheet1").Activate
  22. Worksheets("Sheet1").Range("A6").CopyFromRecordset MyRS
  23.  
  24. MyRS.Close
  25. Set MyRS = Nothing
  26. End Sub
Dec 13 '07 #2
FishVal
2,653 Recognized Expert Specialist
I'm very unsure CopyFromRecordset method ever works with DAO.Recordset. Try ADODB.Recordset instead if it doesn't.

Regards,
Fish
Dec 13 '07 #3
Nathan H
104 New Member
I'm very unsure CopyFromRecordset method ever works with DAO.Recordset. Try ADODB.Recordset instead if it doesn't.

Regards,
Fish
I found a very simple work around. I export the data to a generic excel spreadsheet, and then have the Template Excel file query the generic, rather than go directly to the database. It adds a step and an extra spreadsheet, but was fairly quick and painless...

Thanks for your input
Dec 13 '07 #4
ADezii
8,834 Recognized Expert Expert
I'm very unsure CopyFromRecordset method ever works with DAO.Recordset. Try ADODB.Recordset instead if it doesn't.

Regards,
Fish
Hello FishVal, the code in Post #2 has been tested and is functional.
Dec 13 '07 #5
FishVal
2,653 Recognized Expert Specialist
Hello FishVal, the code in Post #2 has been tested and is functional.
Ok. The following code fails with
403: Class does not support Automation or does not support expected interface

XP SP2, Office 2003
Expand|Select|Wrap|Line Numbers
  1. Public Sub ExportDAOfromWS()
  2.  
  3.     Dim appExcel As Excel.Application
  4.     Dim rs As DAO.Recordset
  5.     Dim ws As DAO.Workspace
  6.     Dim db As DAO.Database
  7.  
  8.     Set appExcel = CreateObject("Excel.Application")
  9.     Set ws = CreateWorkspace("", "admin", "", dbUseJet)
  10.     Set db = OpenDatabase("C:\db2.mdb", True)
  11.     Set rs = db.OpenRecordset("t1", dbOpenSnapshot)
  12.  
  13.     With appExcel
  14.         .UserControl = True
  15.         .Visible = True
  16.         With .Workbooks.Add.Worksheets(1)
  17.             .Activate
  18.             .Range("A1").CopyFromRecordset rs      '<------- Fails here
  19.         End With
  20.     End With
  21.  
  22.     rs.Close
  23.  
  24.     Set rs = Nothing
  25.     Set db = Nothing
  26.     Set ws = Nothing
  27.     Set appExcel = Nothing
  28.  
  29. End Sub
  30.  
ADODB.Recordset works just fine.

Oops! Just have noticed. Your code runs in Excel application.
Dec 13 '07 #6
ADezii
8,834 Recognized Expert Expert
Ok. The following code fails with
403: Class does not support Automation or does not support expected interface

XP SP2, Office 2003
Expand|Select|Wrap|Line Numbers
  1. Public Sub ExportDAOfromWS()
  2.  
  3.     Dim appExcel As Excel.Application
  4.     Dim rs As DAO.Recordset
  5.     Dim ws As DAO.Workspace
  6.     Dim db As DAO.Database
  7.  
  8.     Set appExcel = CreateObject("Excel.Application")
  9.     Set ws = CreateWorkspace("", "admin", "", dbUseJet)
  10.     Set db = OpenDatabase("C:\db2.mdb", True)
  11.     Set rs = db.OpenRecordset("t1", dbOpenSnapshot)
  12.  
  13.     With appExcel
  14.         .UserControl = True
  15.         .Visible = True
  16.         With .Workbooks.Add.Worksheets(1)
  17.             .Activate
  18.             .Range("A1").CopyFromRecordset rs      '<------- Fails here
  19.         End With
  20.     End With
  21.  
  22.     rs.Close
  23.  
  24.     Set rs = Nothing
  25.     Set db = Nothing
  26.     Set ws = Nothing
  27.     Set appExcel = Nothing
  28.  
  29. End Sub
  30.  
ADODB.Recordset works just fine.

Oops! Just have noticed. Your code runs in Excel application.
If the t1 Recordset contains an OLE Object Field, you may also encounter the same Error.
Dec 14 '07 #7
FishVal
2,653 Recognized Expert Specialist
If the t1 Recordset contains an OLE Object Field, you may also encounter the same Error.
[t1] contains numerical, text and boolean fields.
Interesting that CopyFromRecordset method works with DAO.Recordset when code runs in Excel but fails in Access.
Problem with Excel objects automation?
Dec 14 '07 #8
ADezii
8,834 Recognized Expert Expert
[t1] contains numerical, text and boolean fields.
Interesting that CopyFromRecordset method works with DAO.Recordset when code runs in Excel but fails in Access.
Problem with Excel objects automation?
Interesting that CopyFromRecordset method works with DAO.Recordset when code runs in Excel but fails in Access.
Hello FishVal, just thought you wanted to know that the code in the previous Post works flawlessly. If you like, I can send you the Test DB that I used. It just didn't seem right that it would fail within Access.
Dec 14 '07 #9
FishVal
2,653 Recognized Expert Specialist
Hello FishVal, just thought you wanted to know that the code in the previous Post works flawlessly. If you like, I can send you the Test DB that I used. It just didn't seem right that it would fail within Access.
Oh, I know the code works in Excel via opening Access database in DAO.Workspace.
It fails when CopyFromRecordset method is invoked via automation in Access module with DAO.Recordset as argument. Again, replacing DAO.Recordset with ADODB.Recordset makes it run normally.
I can send you xls and mdb with the code illustrating this phenomenon if you want.
Dec 14 '07 #10
ADezii
8,834 Recognized Expert Expert
Oh, I know the code works in Excel via opening Access database in DAO.Workspace.
It fails when CopyFromRecordset method is invoked via automation in Access module with DAO.Recordset as argument. Again, replacing DAO.Recordset with ADODB.Recordset makes it run normally.
I can send you xls and mdb with the code illustrating this phenomenon if you want.
You really peaked my curiosity on this one, if you could send me the .xls and .mdb, I would really appreciate it. I'll send you mt E-Mail Address in a PM. Thanks, FishVal.
Dec 14 '07 #11

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: Gary Wright | last post by:
I have an Access 2K database split into front and back. Quite often the users want to do some data analysis that I have not created a report for so they want to export some subset of the data into...
4
by: Anthony Cuttitta Jr. | last post by:
I'm working on some procedures where Access queries are exported to Excel, and then later on, those same workbooks are openned, and I need to target a specific original sheet. Sometimes there will...
1
by: Ellen Manning | last post by:
I'm trying to export an Excel2K spreadsheet to A2K. Here is a sample of the Excel spreadsheet: LastName FirstName Hours Location HoursPercent Doe John ...
1
by: setterst | last post by:
I am quite new to VBA and Access, but I am trying to figure out how to export specific values from a table in Access, so I can save it in a given cell in Excel. I have been able to figure out how...
8
by: Jerome Ranch | last post by:
Okay So I've got pivot tables setup in Access 2003. Only about 30K records in the current 2005 databases...the pivots summarize the info in a number of nice ways. I need to get the pivot tables...
1
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with databases. If someone could help me with this issue I'm...
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...
2
by: Access user | last post by:
My apologies for crossposting this, but I did not get any response in microsoft.public.access ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.