Bring the heading data in a sql query

G

gatarossi

Dear all,

Is it possible to bring the heading information in this query?

Sub return_data_byDept()

Dim adoconn As ADODB.Connection
Dim adors As ADODB.Recordset
Dim sql As String
Dim filenm As String
Dim xlsht As Excel.Worksheet

Set xlsht = Sheets("db by Dept")

filenm = ThisWorkbook.Path & "\bd_lg_expenses.mdb"

Application.ScreenUpdating = False

'xlsht.Visible = xlSheetVisible

xlsht.Select
xlsht.Range(Cells(1, 1), Cells(65536, 256)).ClearContents

sql = "TRANSFORM Sum(tbl_by_dept.amt) AS SomaDeamt "
sql = sql & "SELECT Right([acct_cd],6) AS acct_code "
sql = sql & "FROM tbl_by_dept "
sql = sql & "GROUP BY Right([acct_cd],6) "
sql = sql & "PIVOT tbl_by_dept.month ;"

Call getCn(adoconn, adors, sql, filenm, "", "")
xlsht.Cells(1, 1).CopyFromRecordset adors

'xlsht.Visible = xlSheetVeryHidden

Sheets("by Dept").Select

Application.ScreenUpdating = True


adors.Close
adoconn.Close

Set adors = Nothing
Set adoconn = Nothing
Set xlsht = Nothing

End Sub

Thanks in advance!

André.
 

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

'*' in sql instruction 0
Bring Data from Access 3
Unique Values 2
Database in Excel 0
Bring Data From Access in a Form 0
SQL instruction 1
SQL - Sum Values 0
CopyFromRecordset 1

Top