Using the Open Database Method : Access ADO « Access « VBA / Excel / Access / Word






Using the Open Database Method

 
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

 








Related examples in the same category

1.Creating a New Microsoft Access Database Using ADO
2.Refreshing a Link
3.Deleting Records via ADO