I've got code that builds a DAO recordset from a table, and then pastes
the recorset in a specified area in an Excel worksheet.
*************** *************** *************** ******
Function AccessToExcelAu tomationEP()
Dim db As Database
Dim rsCMRSummary As DAO.Recordset
Dim wbkNew As Excel.Workbook
Dim wksNew As Excel.Worksheet
Dim rngCurrSummary As Excel.Range
Set db = CurrentDb
'Opens the recordset
Set rsCMRSummary = db.OpenRecordse t("Select Descr, TotalEmployees,
MinMales, ([MinMales]/[TotalEmployees]) as '%MaleMin' from
tblEPFinal_MinM aleFemale;")
'Opens a new Excel workbook, and creates a new worksheet for the report
Set appExcel = New Excel.Applicati on
Set wbkNew = appExcel.Workbo oks.Add
Set wksNew = wbkNew.Workshee ts.Add
appExcel.Visibl e = True
'Selects the Excel range, and then pastes the recordset into that range
Set rngCurrSummary = wksNew.Range("H 21:K32")
rngCurrSummary. CopyFromRecords et rsCMRSummary
End Function
*************** *************** *************** ***
The code works as intended, however, if I have a row in the table that
all the values are "0", the recorset holds all the rows, but does not
paste from the row with all 0's to the end of the recordset.
i.e.
Professionals 10 10 10
Sales 10 10 10
Technical 0 0 0
Labor 99 99 99
will only print the first two rows.
But if I have:
Professionals 10 10 10
Sales 10 10 10
Technical 15 15 15
Labor 99 99 99
Then all four rows paste to Excel.
I would appreciate any help that you could provide. 2 6610
Maybe it's a divide by zero / #Error issue. Try "Select Descr,
TotalEmployees,
MinMales, iif([TotalEmployees]=0,Null,[MinMales]/[TotalEmployees]) as
'%MaleMin' from
tblEPFinal_MinM aleFemale;"
Ken
Thank you for your reply.
I kept working on this. The problem was that I was creating the value
in "%MaleMin' when I opened the recordset, versus when I populated the
table in the first place.
I did have to include some conditions for if the numerator or
denominator were 0. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rick Brown |
last post by:
Office97 / Access97 / Win2000
I'm using CopyFromRecordset to load four Excel sheets in the same
workbook with approx. 15,000 rows by 36 columns.
The process seems slow and I would like to know if there is a faster
method?
.Range("A2").CopyFromRecordset rsTotalPurchasedParts
Thanks for any help, Rick
|
by: info |
last post by:
I have an Access Application which happily uses CopyFromRecordset to
transfer values from an access query via a recordset to an excel
spreadsheet, this works on three machines. However, when I try it on a
fourth machine (same versions of Excel & Access), no records are
transfered (I check that the recordset contains records which it does).
...
|
by: al |
last post by:
Greetings,
I'm wondering if Excel object CopyFromRecordset is still supported in
VB.NET?? If not, what is the alternative, looping through dataset????
MTIA,
Grawsha
|
by: zhollywood |
last post by:
OK... I'm not VBA illiterate, but I'm a BA trying to maintain a
code-heavy Access 2002 (XP OS) front-end attached to Oracle tables. I
have an export to Excel button that worked before the SP2 upgrade, and
didn't work afterwards. Research shows me the upgrade caused a problem
with a memo field in the export, causing the CopyFromRecordset of...
|
by: cycnus |
last post by:
Does anyone else have the same issue?
I'm using Access 2007 and trying to export a DAO recordset to excel using
CopyFromRecordset but I systematically get a "Run-Time error 430, Class does
not support Automation or does not support expected interface".
When I use ADO, it works fine.
Everything is up-to-date on my PC, doesn't seems to be any...
| |
by: Cor Pruim |
last post by:
I have a very strange problem. I have written a Windows Service with VS2003 in vb.net. This service does some calculations and after that it needs to produce some Excel reports by getting data from an Oracle database.
This has been working fine for two years and it still is working fine in our production environment. But after installing a new...
|
by: il0postino |
last post by:
Apologies in advance for this newbie question!
I have an Access form with an unbound embedded Excel chart on it(Called, OLEUnbound39) (Done on Access form by Insert > Object > Microsoft excel chart)
I would like to place some records in to the underliing sheet and display the chart of this data using VBA.
I use CopyFromRecordset. The code...
|
by: mac6777 |
last post by:
I am having a problem with the CopyFromRecordset function in VBA Access. I am attempting to run VBA in an Access Database that copies query results into an Excel spreadsheet. The VBA opens an Excel template, runs the query, then attempts to copy the query as a recordset into the Excel spreadsheet. The problem is that I get the following error...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |