Monday, 25 June 2012

Ex5: VBA - BAND Operator in ADO

Illustrate the BAND operator with literals. (ADO only.) in VBA

Function ShowBand()
    Dim rs As New ADODB.Recordset
    rs.Open "SELECT (2 BAND 4) AS Result;", CurrentProject.Connection
    ShowBand = rs!Result
    rs.Close
    Set rs = Nothing
End Function

Function TestBand()
    'Purpose:   Illustrate BAND (binary AND) operator. (ADO only.)
    Dim rs As New ADODB.Recordset
    Dim strSql As String
    
    strSql = "SELECT MyBitField, (MyBitField BAND 2) <> 0 As MyResult FROM MyTable;"
    rs.Open strSql, CurrentProject.Connection
    
    Do While Not rs.EOF
        Debug.Print rs!MyBitfield, rs!MyResult
        rs.MoveNext
    Loop
    
    rs.Close
    Set rs = Nothing
End Function

No comments:

Post a Comment