Solved Filter subform (1 Viewer)

tihmir

Registered User.
Local time
Yesterday, 22:14
Joined
May 1, 2018
Messages
216
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: 400

Gasman

Enthusiastic Amateur
Local time
Today, 06:14
Joined
Sep 21, 2011
Messages
10,531
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, 01:14
Joined
May 21, 2018
Messages
6,356
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
Yesterday, 22:14
Joined
May 1, 2018
Messages
216
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, 01:14
Joined
May 21, 2018
Messages
6,356
@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: 392

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:14
Joined
May 7, 2009
Messages
16,393
maybe same with majp.
 

Attachments

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

Users who are viewing this thread

Top Bottom