Sub OpenExternalSQL()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset
cnn.Open "Provider=sqloledb;" & _
"Data Source=(local);" & _
"Initial Catalog=yourDb;" & _
"User Id=sa;Password=; "
Set rst = cnn.Execute("Select * from Employees")
Do Until rst.EOF
Debug.Print rst.Fields(0).Value
rst.MoveNext
Loop
'Close the connection
cnn.Close
End Sub
|