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 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. - 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
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
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
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.
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 -
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.
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 -
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.
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?
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.
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.
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.
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: 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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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: 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...
|
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...
| |