How to import SQL Stored Procedure to excel, including columns headings?

  • Thread starter Thread starter zachi.fernaldes
  • Start date Start date
Z

zachi.fernaldes

Hi all,
I've faced with a problem:
I'm executing a script in excel vba which send parameters to SQL stored
procedure and import it's results to excel work sheet, as you can see
below:

ParArray = Array(Array("@Planet", adVarChar, 50, strSelectedPlanet), _
Array("@StartTime", adDate, 50, strStartTime), _
Array("@EndTime", adDate, 50, strEndTime))

Set rsTemp = ExecSP("USPS_sysLoginsInformation_RT", 3, ParArray)

' Copy the records into cell A1 on Sheet1.
Sheet1.Range("A1").CopyFromRecordset rsTemp

The Problem is that i receive the data without it's columns headings
names. How can i get the data with the fields names?

Thanks for your help.
 
I haven't done any work in Excel for a long time now, so I'll leave the
placing of the field names into the cells to you, but here's an example of
how to retrieve the field names from the recordset ...

Public Sub WalkFieldsDAO()

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim fld As DAO.Field

Set db = CurrentDb
Set rst = db.OpenRecordset("TestTable")
For Each fld In rst.Fields
Debug.Print fld.Name
Next fld
rst.Close

End Sub

Public Sub WalkFieldsADO()

Dim rst As ADODB.Recordset
Dim fld As ADODB.Field

Set rst = New ADODB.Recordset
Set rst.ActiveConnection = CurrentProject.Connection
rst.Open "TestTable"
For Each fld In rst.Fields
Debug.Print fld.Name
Next fld
rst.Close

End Sub
 

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

Back
Top