Get Access 2007 data w heading in Excel 2007

Microsoft Office excel 2007 visual basic...
September 23, 2010 at 10:35:33
Specs: Windows XP
Hello,

How do you get the column headings when you try to get MS Access 2007 query data into MS Excel 2007? This is my code. Thank you

Sub GetProductSummaryData()
Dim cnt As New ADODB.Connection
Dim rst As New ADODB.Recordset
cnt.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=H:\Project\\Reporting Db.accdb;Persist Security Info=False;"
rst.Open "Select * From [Product Summary]", cnt
Range("A1").CopyFromRecordset rst
End Sub


See More: Get Access 2007 data w heading in Excel 2007

Report •

#1
September 23, 2010 at 14:07:43
Untested, as I don't have a DB handy at the moment:
Sub GetProductSummaryData()
  Dim cnt As New ADODB.Connection
  Dim rst As New ADODB.Recordset
  cnt.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=H:\Project\\Reporting Db.accdb;Persist Security Info=False;"
  rst.Open "Select * From [Product Summary]", cnt
  Dim f As ADODB.Field
  Dim c As Range
  Set c = Cells(1)
  For Each f In rst.Fields
    c = f.Name
    Set c = c.Offset(0, 1)
  Next 'f
  Range("A2").CopyFromRecordset rst
End Sub


Report •
Related Solutions


Ask Question