CopyfromRecordset reverses query columns

J

Jen

Hi,
I am using CopyFromRecordset to copy a query from Access into Excel. I
am getting the data that I want, but the values that should be in
column B are in Column A, and vice versa. Even if I reverse the column
order in my query, I get the same incorrect order.

I have verified that the query gives the correct result in Access. Any
ideas on what I could be doing wrong?

Here is my code:

CDaoDatabase db;
CDaoRecordset rs;

CString sConn = "C:\\mydbase.mdb";
db.Open(sConn, FALSE, FALSE);
rs.m_pDatabase = &db;

CDaoQueryDef query3(&db);

CString finalQuery;
finalQuery = "SELECT q.f, q.v FROM qJen2 As q WHERE q.a >5 ORDER BY
q.a DESC";
query3.Create(NULL,finalQuery.GetBuffer(0));
query3.SetParamValue( "[Start Date]",(COleVariant)vDateTimeS);
query3.SetParamValue( "[End Date]", (COleVariant)vDateTimeE);
query3.SetParamValue( "[Start Date 2]",(COleVariant)vDateTimeS2);
query3.SetParamValue( "[End Date 2]", (COleVariant)vDateTimeE2);
rs.Open(&query3);


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

Jen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top