Filtering subform on change in textboxes (1 Viewer)

guestbb

Registered User.
Local time
Yesterday, 16:18
Joined
Jul 14, 2015
Messages
44
I made the code to filter a subform from a main form. In the main form i have multiple textboxes and comboboxes that filter the subform. In the code they are connected, so they filter already filtered subform if i have used one or more of textbox or comboboxes already.
It works alright when I use comboxes or when I paste the text in the textboxes, but it doesnt filter when while i type (On Change) in textboxes or comboboxes.
The code for filtering is in a different sub so i can easy put it in on textboxes and comboboxes.
Does anyone have a solution for this so that it works on change also (when I start typing that it filters) because it doesn't do that, only selecting in a combobox or pasting into textbox.

I have tried adding .Text to comboboxes and textboxes but it returns a error "run time error 2185, "You can't reference a property or method for a control unless the control has the focus ..."."
Adding .Value also didnt made any change, but it was without the error.

EDIT: Also it starts filtering, but strange when I use backspace to delete what I typed.



Code:
Private Sub txtVlaV_Change()
    FilterCode
End Sub


Private Sub FilterCode()
   Dim strWhere As String
    Dim lngLen As Long
    Const conJetDate = "\#dd\/mm\/yyyy\#"
    
    If Not IsNull(Me.cboKatV) Then
        strWhere = strWhere & "([KatV] Like '*" & Me.cboKatV & "*') AND "
    End If

    If Not IsNull(Me.cboMarkaV) Then
        strWhere = strWhere & "([MarkaV] Like '*" & Me.cboMarkaV & "*') AND "
    End If
    
    If Not IsNull(Me.txtModelV) Then
        strWhere = strWhere & "([ModelV] Like '*" & Me.txtModelV & "*') AND "
    End If
    
    If Not IsNull(Me.txtTipM) Then
        strWhere = strWhere & "([TipMotora] Like '*" & Me.txtTipM & "*') AND "
    End If
    
    If Not IsNull(Me.txtRig) Then
        strWhere = strWhere & "([Rig] Like '*" & Me.txtRig & "*') AND "
    End If
    
    If Not IsNull(Me.txtBrSaj) Then
        strWhere = strWhere & "([BrSaj] Like '*" & Me.txtBrSaj & "*') AND "
    End If
    
    If Not IsNull(Me.cboVrGor) Then
        strWhere = strWhere & "([VrGor] Like '*" & Me.cboVrGor & "*') AND "
    End If
    
    If Not IsNull(Me.cboVrstPog) Then
        strWhere = strWhere & "([VrstPog] Like '*" & Me.cboVrstPog & "*') AND "
    End If
    
    If Not IsNull(Me.txtVlaV) Then
        strWhere = strWhere & "([VlaV] Like '*" & Me.txtVlaV & "*') AND "
    End If
    
    If Not IsNull(Me.txtKorV) Then
        strWhere = strWhere & "([KorV] Like '*" & Me.txtKorV & "*') AND "
    End If
    
    If Not IsNull(Me.txtOdDat) Then
        strWhere = strWhere & "([DatV] >= " & Format(Me.txtOdDat, conJetDate) & ") AND "
    End If
    
    If Not IsNull(Me.txtDoDat) Then
        strWhere = strWhere & "([DatV] >= " & Format(Me.txtDoDat, conJetDate) & ") AND "
    End If
    
    lngLen = Len(strWhere) - 5
    If lngLen <= 0 Then
        Exit Sub
    Else
        strWhere = Left$(strWhere, lngLen)

        Me.subPretV.Form.Filter = strWhere
        Me.subPretV.Form.FilterOn = True
        Me.subPretV.Form.Requery
    End If
End Sub
 
Last edited:

guestbb

Registered User.
Local time
Yesterday, 16:18
Joined
Jul 14, 2015
Messages
44
I alredy looked at all of that but it didnt help me
When I put all the textboxes and comboboxes to use code AfterUpdate and add .Value to end of them in the code it work. but i have to press enter after i type. and that is not what i want.
Is there any way to do it with Change function??
 

Users who are viewing this thread

Top Bottom