Monday, 25 June 2012

Ex2: VBA - Open a recordset using ADO

Open a recordset using ADO in VBA

Function AdoRecordsetExample()
    'Purpose:   Open a recordset using ADO.
    Dim rs As New ADODB.Recordset
    Dim strSql As String
    
    strSql = "SELECT MyField FROM MyTable;"
    rs.Open strSql, CurrentProject.Connection
    
    Do While Not rs.EOF
        Debug.Print rs!MyField
        rs.MoveNext
    Loop
    
    rs.Close
    Set rs = Nothing
End Function

No comments:

Post a Comment