Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Format data in Excel after using copyfromrecordset | Excel Discussion (Misc queries) | |||
Excel VBA - CopyFromRecordset (ADO) Problems with 107000 records | Excel Programming | |||
CopyFromRecordset with large amount of data | Excel Programming | |||
Excel 2003 - 'CopyFromRecordset' Error | Excel Programming | |||
CopyFromRecordset - Is there a way to filter data that's copied? | Excel Programming |