QuietRiot
11-15-2007, 04:27 PM
I'm using this code below to import data into a spreadsheet. The problem is it doesn't include the headers/titles of the columns. How do I include field names? I know if I record I see something similiar to .fieldnames = true
here is the code I would like to work with instead..
Dim Cn As ADODB.Connection
Dim Server_Name As String
Dim Database_Name As String
Dim User_ID As String
Dim Password As String
Dim SQLStr As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Server_Name = "servername"
Database_Name = "dbname"
User_ID = "******"
Password = "****"
SQLStr = "select * from dbo.TransactionInformation where fundgroupnumber = '090' and postingdate =" & QueryDate
Set Cn = New ADODB.Connection
Cn.Open "Driver={SQL Server};Server=" & Server_Name & ";Database=" & Database_Name & _
";Uid=" & User_ID & ";Pwd=" & Password & ";"
rs.Open SQLStr, Cn, adOpenStatic
With Worksheets("Query").Range("A2")
.ClearContents
.CopyFromRecordset rs
End With
rs.Close
Set rs = Nothing
Cn.Close
Set Cn = Nothing
any help,
thanks
here is the code I would like to work with instead..
Dim Cn As ADODB.Connection
Dim Server_Name As String
Dim Database_Name As String
Dim User_ID As String
Dim Password As String
Dim SQLStr As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Server_Name = "servername"
Database_Name = "dbname"
User_ID = "******"
Password = "****"
SQLStr = "select * from dbo.TransactionInformation where fundgroupnumber = '090' and postingdate =" & QueryDate
Set Cn = New ADODB.Connection
Cn.Open "Driver={SQL Server};Server=" & Server_Name & ";Database=" & Database_Name & _
";Uid=" & User_ID & ";Pwd=" & Password & ";"
rs.Open SQLStr, Cn, adOpenStatic
With Worksheets("Query").Range("A2")
.ClearContents
.CopyFromRecordset rs
End With
rs.Close
Set rs = Nothing
Cn.Close
Set Cn = Nothing
any help,
thanks