Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default MFC - CopyFromRecordset - Copy data to Excel

Hi,
I am trying to copy a set of data from my Access database to Excel. I am
using an MFC program where I have embedded an excel spreadsheet into my MFC
Dialog. I reviewed the knowledgebase articles and found:
http://support.microsoft.com/kb/243394/en-us
This article showed me how to copy a set of data, and I tried it and it
works. The problem is that it starts a new instance of excel and my data is
there and not in my MFC Dialog.

I revised the code using the existing Excel workbook/worksheet and I get an
exception on the call to CopyFromRecordset. Here is my code:

//Then get the first worksheet in the workbook
wsSet = wb.GetWorksheets();
ws = wsSet.GetItem(COleVariant((short)(1)));
charts = wb.GetCharts();
chart = charts.GetItem(COleVariant((short)(1)));

CDaoDatabase db;
CDaoRecordset rs;
CString sConn;
long lNumCols;

//Get a recordset that represents all the records in the Products
//table of the sample Northwind database
sConn.Format("%s\\Test.mdb", m_DWorkingDir);
db.Open(sConn, FALSE, FALSE);
rs.m_pDatabase = &db;
CDaoQueryDef query(&db);
query.Open("Main Screen");

rs.Open(&query);

lNumCols = rs.GetFieldCount();

Range oRange;
COleDispatchDriver rs2;
rs2.AttachDispatch((LPDISPATCH) rs.m_pDAORecordset);
oRange = ws.GetRange(COleVariant("A2"), vOpt);
oRange.CopyFromRecordset((LPUNKNOWN) rs.m_pDAORecordset,vOpt, vOpt);

Any ideas!?!? I really need some help to figure this out!
Jennifer
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Format data in Excel after using copyfromrecordset jj Excel Discussion (Misc queries) 2 June 13th 07 06:48 AM
Excel VBA - CopyFromRecordset (ADO) Problems with 107000 records Philip Excel Programming 8 March 24th 05 08:53 AM
CopyFromRecordset with large amount of data rweide Excel Programming 9 October 18th 04 03:25 PM
Excel 2003 - 'CopyFromRecordset' Error Chris Wiley Excel Programming 2 October 2nd 04 05:42 AM
CopyFromRecordset - Is there a way to filter data that's copied? Mark[_22_] Excel Programming 1 November 6th 03 05:10 AM


All times are GMT +1. The time now is 11:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"