I'm trying to pull in information using an ADO connection and I can't quite visualize how the column headings can be written to my XL sheet. Any help would be great.
Sub Get_Info()
Dim cnt As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strSQL As String
Dim strdb As String
Dim r As Integer
Dim c As Integer
Dim fld As Field
r = 1
c = 1
strdb = "D:\db2.mdb"
cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strdb & ";"
strSQL = "SELECT * FROM tblmytable;"
Set rst = cnt.Execute(strSQL)
rst.MoveFirst
Do While Not rst.EOF And Not rst.BOF
For Each fld In rst.Fields
Cells(r, c) = fld
c = c + 1
Next fld
rst.MoveNext
c = 1
r = r + 1
Loop
End Sub
Thanks, Rib
Bartender:Hey aren't you that rope I threw out an hour ago?
Rope:No, I'm a frayed knot.
Sub Get_Info()
Dim cnt As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strSQL As String
Dim strdb As String
Dim r As Integer
Dim c As Integer
Dim fld As Field
r = 1
c = 1
strdb = "D:\db2.mdb"
cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strdb & ";"
strSQL = "SELECT * FROM tblmytable;"
Set rst = cnt.Execute(strSQL)
rst.MoveFirst
Do While Not rst.EOF And Not rst.BOF
For Each fld In rst.Fields
Cells(r, c) = fld
c = c + 1
Next fld
rst.MoveNext
c = 1
r = r + 1
Loop
End Sub
Thanks, Rib
Bartender:Hey aren't you that rope I threw out an hour ago?
Rope:No, I'm a frayed knot.