Bring in column title with query in VBA like Excel's query wizard

WHen using Excel's quiery wizard, it brings in the column titles, but is there a way to set a VBA SQL statement to do the same?  That is, rather than having to name the feilds with code in VBA, can the SQL statement be set to bring the column headers in as well?
With Workbooks(strWbkName).Worksheets("DataSource") 'Current month's Green Package destination workbook
    strSQL = "SELECT [ClientCode] , [Fund/Sector],[%NotionalScaling], [%NotionalBench], " & _
          "[SpreadDurationContributionPort], [SpreadDurationContributionBench] " & _
          "FROM " & strRangeName & " "
    Set rst = New ADODB.Recordset
     Call rst.Open(strSQL, strCnn, CursorTypeEnum.adOpenForwardOnly, LockTypeEnum.adLockReadOnly, CommandTypeEnum.adCmdText)
            strLastRow = .Range(strDestination & "65536").End(xlUp).Address
            intRowNum = (.Range(strLastRow).Row) + 1
     Call .Range(strDestination & intRowNum).CopyFromRecordset(rst)  'Need to dynamcially determin last cell
End With

Open in new window

Sandra SmithRetiredAsked:
Who is Participating?
 
dlmilleCommented:
0
 
dlmilleCommented:
Select Column_Name from table should return all column names.

Dave
0
 
Sandra SmithRetiredAuthor Commented:
Thanks Dave.

Sandra
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.