Solved Filter subform (2 Viewers)

tihmir

Registered User.
Local time
Today, 07:14
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

  • Database1.accdb
    3.3 MB · Views: 495

Gasman

Enthusiastic Amateur
Local time
Today, 14:14
Joined
Sep 21, 2011
Messages
14,053
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?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 10:14
Joined
May 21, 2018
Messages
8,463
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
 

tihmir

Registered User.
Local time
Today, 07:14
Joined
May 1, 2018
Messages
257
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

You've got your good things, and you've got mine.
Local time
Today, 10:14
Joined
May 21, 2018
Messages
8,463
@MajP, when I replace your code and press search button it show me that I have not chosen criteria
Works for me.
 

Attachments

  • MajP_Database1.accdb
    736 KB · Views: 491

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:14
Joined
May 7, 2009
Messages
19,175
maybe same with majp.
 

Attachments

  • Database1 (1).accdb
    3.3 MB · Views: 496

Users who are viewing this thread

Top Bottom