fboehlandt
Active Member
- Joined
- Sep 9, 2008
- Messages
- 334
Hi everyone
I am using the CopyFromRecordset method to transfer data from Access to an Excel worksheet. The query (CmdStrExec) yields a table with eight columns. However, I would like to transfer columns 2 to 8 only. I have the code below to transfer all data:
Unfortunately, I cannot easily remove said column when running the query. The source data is normalised and is pivoted using said column as first column before export. For completeness sake I include the SQL query as well.
CmdStrExec:
Any help is greatly appreciated
I am using the CopyFromRecordset method to transfer data from Access to an Excel worksheet. The query (CmdStrExec) yields a table with eight columns. However, I would like to transfer columns 2 to 8 only. I have the code below to transfer all data:
Code:
Set conn = CreateObject("ADODB.Connection")
conn.Open sConnString
Set rs = conn.Execute(CmdStrExec)
'Check Data
If Not rs.EOF Then[INDENT]'Transfer result to Workbook[/INDENT]
[INDENT]TargetCell.CopyFromRecordset rs
'Close the recordset[/INDENT]
[INDENT]rs.Close[/INDENT]
[INDENT]ConnectSqlServer = "Import complete"[/INDENT]
Else[INDENT]rs.Close
ConnectSqlServer = "No records returned"[/INDENT]
End If
Unfortunately, I cannot easily remove said column when running the query. The source data is normalised and is pivoted using said column as first column before export. For completeness sake I include the SQL query as well.
CmdStrExec:
Code:
TRANSFORM First(Amount)
SELECT SrcUD2
FROM source
WHERE LocName="myLoc" AND Entity="LE01" AND PeriodName="QA - 2014" AND ScenarioName="Actual"
AND (Account="col1" Or Account="col2" Or Account="col3" Or Account="col4" Or Account="col5" Or Account="col6" Or Account="col7")
AND (SrcUD2="row1" Or SrcUD2="row2" Or SrcUD2="row3" Or SrcUD2="row4" Or SrcUD2="row5" Or SrcUD2="row6" Or SrcUD2="row7" Or SrcUD2="row8" Or SrcUD2="row9")
GROUP BY SrcUD2
PIVOT Account
Any help is greatly appreciated