Solved Filter subform

tihmir

Registered User.
Local time
Yesterday, 22:39
Joined
May 1, 2018
Messages
257
Hi all, I need some help to filter my subform, which is made by query .
What I miss and what needs to be added to the code to work?
Code:
Private Sub cmdSearch_Click()

    Dim strQuery As String
    Dim strWhere As String
    Dim lngLen As Long
    Const conJetDate = "\#mm\/dd\/yyyy\#"

    strQuery = "qry_Inspections"
    
    If Not IsNull(Me.cboWorker) Then
        strWhere = strWhere & "([Worker] = """ & Me.cboWorker & """) AND "
    End If

    If Not IsNull(Me.txtFrom) Then
        strWhere = strWhere & "([DateTask] >= " & Format(Me.txtFrom, conJetDate) & ") AND "
    End If

    If Not IsNull(Me.txtTo) Then
        strWhere = strWhere & "([DateTask] < " & Format(Me.txtTo + 1, conJetDate) & ") AND "
    End If

    lngLen = Len(strWhere) - 5
    If lngLen <= 0 Then
        MsgBox "No criteria", vbInformation, "Nothing to do."
    Else                    '
        strWhere = Left$(strWhere, lngLen)

        Me.Filter = strWhere
        Me.FilterOn = True

    End If
End Sub
 

Attachments

Debug.print strWhere and see what that displays. Plus where is that code as it filters the form the button is on, even if it works?
 
Code:
    If lngLen <= 0 Then
        MsgBox "No criteria", vbInformation, "Nothing to do."
        With Me.qry_Inspections_subform.Form
          .Filter = ""
          .FilterOn = False
        End With
    Else                    '
        strWhere = Left$(strWhere, lngLen)
        Debug.Print strWhere
        With Me.qry_Inspections_subform.Form
          .Filter = strWhere
          .FilterOn = True
        End With
    End If
 
Debug.print strWhere and see what that displays. Plus where is that code as it filters the form the button is on, even if it works?
The buttons (unbounded) are on the Main form (form header). If it is convenient can you look at the Database1, please?
MajP, when I replace your code and press search button it show me that I have not chosen criteria
 
@MajP, when I replace your code and press search button it show me that I have not chosen criteria
Works for me.
 

Attachments

Users who are viewing this thread

Back
Top Bottom