Hi all,
I'm trying to use ADO to import the results of an SQL query into and Excel spreadsheet. All works fine except it's not pulling the header row back. From browsing the the net it seems I need a 'HDR=Yes' somewhere but I can't suss out where. Can anyone help? Code below:
Part one
Part two (the ADO bit)
Thanks in advance,
I'm trying to use ADO to import the results of an SQL query into and Excel spreadsheet. All works fine except it's not pulling the header row back. From browsing the the net it seems I need a 'HDR=Yes' somewhere but I can't suss out where. Can anyone help? Code below:
Part one
Code:
Sub GetOrderDetail()
Dim userid As String
Dim password As String
Dim SQLS As String
Dim destination As String
Worksheets("Order Sheet DETAIL").Range("B8:S20009").ClearContents
userid = "NONFOODFIN"
password = "nonfoodfin"
SQLS = " exec DXWI_PROD_NONFOODFIN_PLAY_PEN.UR77_FWK06_Order_Detail; "
destination = [DownloadOrderDetail].Address
Call ADOExecDataGet(userid, password, SQLS, destination)
End Sub
Part two (the ADO bit)
Code:
Sub ADOExecDataGet(userid, password, SQLS, destination)
Dim Rs As New ADODB.Recordset
Dim TerConnection As New ADODB.Connection
'ensure RecordSet and Connection are closed
On Error Resume Next
Rs.Close
On Error Resume Next
TerConnection.Close
'ODBC Driver for Teradata
myUsername = userid
myPassword = password
TerConnection.Open "DSN=DW Master;" & _
"Uid=" & userid & ";" & _
"Pwd=" & password & ";"
TerConnection.CommandTimeout = 0
Set Rs = TerConnection.Execute(SQLS)
'Rs.Close
'TerConnection.Close
'Import data to destination cell
Range(destination).CopyFromRecordset Rs
End Sub
Thanks in advance,