Search code examples
ms-accessvbams-access-2007

VBA/ACCESS EASY: Query for yes/no field in a table


Looking for a query syntax for vba code that allows to find if a yes/no field = no.

 Set rsStepCalendar = db.OpenRecordset("Select * from tblStepCalendar" & _
                                            "Where (groupNr like '*" & txtGroupNum.Value & "*' )" & _
                                            "AND (CanceledContact = 0)", dbOpenDynaset)

Solution

  • If your SQL statement is accurate, the following should work.

    Dim strSQL AS String
    Dim db AS DAO.Database
    Dim rsStepCalendar AS DAO.Recordset
    
    strSQL = "SELECT" & VbCrLf & _
             "    S.*" & VbCrLf & _
             "FROM tblStepCalendar S" & VbCrLf & _
             "WHERE S.groupNr LIKE '*" &  txtGroupNum.Value & "*'" & VbCrLf & _
             "AND S.CanceledContact = 0"
    
    Set db = CurrentDB
    Set rsStepCalendar = db.OpenRecordset(strSQL, dbOpenDynaset)