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

CopyFromRecordset to Excel Problem

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 AccessToExcelAutomationEP()

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.OpenRecordset("Select Descr, TotalEmployees,
MinMales, ([MinMales]/[TotalEmployees]) as '%MaleMin' from
tblEPFinal_MinMaleFemale;")

'Opens a new Excel workbook, and creates a new worksheet for the report
Set appExcel = New Excel.Application
Set wbkNew = appExcel.Workbooks.Add
Set wksNew = wbkNew.Worksheets.Add
appExcel.Visible = True

'Selects the Excel range, and then pastes the recordset into that range
Set rngCurrSummary = wksNew.Range("H21:K32")
rngCurrSummary.CopyFromRecordset 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.

Nov 13 '05 #1
2 6596
Maybe it's a divide by zero / #Error issue. Try "Select Descr,
TotalEmployees,
MinMales, iif([TotalEmployees]=0,Null,[MinMales]/[TotalEmployees]) as
'%MaleMin' from
tblEPFinal_MinMaleFemale;"

Ken

Nov 13 '05 #2
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.

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
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...
1
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...
2
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
2
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...
2
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...
3
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...
1
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...
11
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
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 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.