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
10 6933
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. - Private Sub CommandButton1_Click()
-
Dim MyDB As DAO.Database, MyRS As DAO.Recordset
-
Dim wk As Workspace, intCols As Integer, intRow As Integer
-
-
' Create Microsoft Jet Workspace object.
-
Set wk = CreateWorkspace("", "admin", "", dbUseJet)
-
-
' Open Database object from saved Microsoft Jet database for exclusive use.
-
Set MyDB = wk.OpenDatabase("C:\Test\Test.mdb", True)
-
-
' Open Recordset based on the Employees Table
-
Set MyRS = MyDB.OpenRecordset("qryEmployees", dbOpenSnapshot)
-
-
'Field Names on Row 5 - then make Bold
-
For intCols = 0 To MyRS.Fields.Count - 1
-
Cells(5, intCols + 1).Value = MyRS.Fields(intCols).Name
-
Next
-
Range("A5:Z5").Select: Selection.Font.Bold = True
-
-
'Bring the data in starting from Row 6
-
Worksheets("Sheet1").Activate
-
Worksheets("Sheet1").Range("A6").CopyFromRecordset MyRS
-
-
MyRS.Close
-
Set MyRS = Nothing
-
End Sub
I'm very unsure CopyFromRecordset method ever works with DAO.Recordset. Try ADODB.Recordset instead if it doesn't.
Regards,
Fish
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
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.
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 -
Public Sub ExportDAOfromWS()
-
-
Dim appExcel As Excel.Application
-
Dim rs As DAO.Recordset
-
Dim ws As DAO.Workspace
-
Dim db As DAO.Database
-
-
Set appExcel = CreateObject("Excel.Application")
-
Set ws = CreateWorkspace("", "admin", "", dbUseJet)
-
Set db = OpenDatabase("C:\db2.mdb", True)
-
Set rs = db.OpenRecordset("t1", dbOpenSnapshot)
-
-
With appExcel
-
.UserControl = True
-
.Visible = True
-
With .Workbooks.Add.Worksheets(1)
-
.Activate
-
.Range("A1").CopyFromRecordset rs '<------- Fails here
-
End With
-
End With
-
-
rs.Close
-
-
Set rs = Nothing
-
Set db = Nothing
-
Set ws = Nothing
-
Set appExcel = Nothing
-
-
End Sub
-
ADODB.Recordset works just fine.
Oops! Just have noticed. Your code runs in Excel application.
Ok. The following code fails with
403: Class does not support Automation or does not support expected interface
XP SP2, Office 2003 -
Public Sub ExportDAOfromWS()
-
-
Dim appExcel As Excel.Application
-
Dim rs As DAO.Recordset
-
Dim ws As DAO.Workspace
-
Dim db As DAO.Database
-
-
Set appExcel = CreateObject("Excel.Application")
-
Set ws = CreateWorkspace("", "admin", "", dbUseJet)
-
Set db = OpenDatabase("C:\db2.mdb", True)
-
Set rs = db.OpenRecordset("t1", dbOpenSnapshot)
-
-
With appExcel
-
.UserControl = True
-
.Visible = True
-
With .Workbooks.Add.Worksheets(1)
-
.Activate
-
.Range("A1").CopyFromRecordset rs '<------- Fails here
-
End With
-
End With
-
-
rs.Close
-
-
Set rs = Nothing
-
Set db = Nothing
-
Set ws = Nothing
-
Set appExcel = Nothing
-
-
End Sub
-
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.
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?
[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.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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 ...
|
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...
|
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...
|
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...
|
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...
|
by: Access user |
last post by:
My apologies for crossposting this, but I did not get any response in
microsoft.public.access
...
|
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...
|
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"....
|
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...
|
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...
|
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...
|
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 =...
|
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...
|
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...
|
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...
| |