Skip to content
Advertisement

Can I convert my query to use select .. like .. or?

Can the query in the code below be converted to Select / Like / Or ?

Private Sub cmdQDef_Click()
    Dim qd As DAO.QueryDef, db As DAO.Database
    Dim ssql As String, WhereName As String, WhereTitle As String

    Set db = CurrentDb

    If Me.FilterName & "" = "" Then
        DoCmd.OpenQuery "q_Search_qdef"
        Exit Sub
    Else
    End If

    ssql = "Select * From Employees"
    Set qd = db.QueryDefs("q_Search_qdef")

    WhereName = "'" & Replace(Me.FilterName, ",", "','") & "'"
    WhereTitle = "'" & Replace(Me.FilterTitle, ",", "','") & "'"    

    ssql = ssql & " Where [First name] In(" & WhereName & ")AND " & _
                     "[Job Title] In (" & WhereTitle & ")"
    qd.SQL = ssql

    DoCmd.OpenQuery "q_Search_qdef"
End Sub

Advertisement

Answer

Yes:

WhereName = "'*" & Replace(Me.FilterName, ",", "','") & "*'"
WhereTitle = "'" & Replace(Me.FilterTitle, ",", "','") & "'"    

ssql = ssql & " Where ([First name] Like " & WhereName & ") OR " & _
                 "([Job Title] In (" & WhereTitle & ")"
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement