Option Explicit
Sub intro()
Dim conn As New Connection
Dim rec As New Recordset
Dim ws As Worksheet
Dim sql$, i&
Set ws = ThisWorkbook.Worksheets("intro")
conn.Open "Provider=microsoft.jet.oledb.4.0;" + _
"Data Source=" + ThisWorkbook.Path + "\nwind.mdb;"
sql = "SELECT LastName, FirstName " & _
"FROM employees ORDER BY LastName, FirstName"
rec.Open sql, conn
While Not rec.EOF
i = i + 1
ws.[a1].Cells(i) = rec!LastName + ", " + rec!FirstName
rec.MoveNext
Wend
rec.Close: conn.Close
End Sub
|