473,287 Members | 3,286 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,287 software developers and data experts.

Access Table Export to specific excel row

Nathan H
104 100+
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 6933
ADezii
8,834 Expert 8TB
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 Expert 2GB
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 100+
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 Expert 8TB
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 Expert 2GB
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 Expert 8TB
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 Expert 2GB
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 Expert 8TB
[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 Expert 2GB
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 Expert 8TB
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 ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...

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.