Full Version: Filter code require correction
UtterAccess Forums > Microsoft® Access > Access Forms
kidmon
I m trying to run this filter command but every time it gives me 0 matches
can anyone help to correct it
Private Sub cmdTrackATP_Click()
Me.Filter = "Forms!frmWIP!ATPCheck = True"
Me.Filter = (Me.Filter + " AND ") & "Forms!frmWIP!PreCheck = False"
Me.Filter = (Me.Filter + " AND ") & "Forms!frmWIP!A5Check = False"
Me.Filter = (Me.Filter + " AND ") & "Forms!frmWIP!SorCheck = False"
Me.Filter = (Me.Filter + " AND ") & "Forms!frmWIP!DownCheck = False"
Me.Filter = (Me.Filter + " AND ") & "Forms!frmWIP!BackCheck = False"
Me.Filter = (Me.Filter + " AND ") & "Forms!frmWIP!Sor2Check = False"
Me.Filter = (Me.Filter + " AND ") & "Forms!frmWIP!FQACheck = False"
Me.Filter = (Me.Filter + " AND ") & "Forms!frmWIP!CompleteCheck = False"
Me.FilterOn = True

End Sub
Alan_G
Try......
!--c1-->
CODE
Private Sub cmdTrackATP_Click()
Dim strFilter As String
Dim frm As Form
Set frm = Forms!frmWIP!ATPCheck
With frm
strFilter = "!ATPCheck = True "
strFilter = strFilter & "AND !PreCheck = False "
strFilter = strFilter & "AND !A5Check = False "
strFilter = strFilter & "AND !SorCheck = False "
strFilter = strFilter & "AND !DownCheck = False "
strFilter = strFilter & "AND !BackCheck = False "
strFilter = strFilter & "AND !Sor2Check = False "
strFilter = strFilter & "AND !FQACheck = False "
strFilter = strFilter & "AND !CompleteCheck = False"
End With
Me.Filter = strFilter
Me.FilterOn = True
Set frm = Nothing
kidmon
i m having a type mismatch with the line
Set frm = Forms!frmWIP!ATPCheck
Just to inform, the check are all check box
Alan_G
Sorry - change it to

Set frm = Forms!frmWIP

For if you're running the code in the same form then just

Set frm = Me

That's what you get for copying and pasting without checking wink.gif
kidmon
i have change it but once u try to run ur code ir request me to input the value for each one
but what i want is it will filter those value out
Alan_G
Sorry, it's definitely time I went to bed!!!
ry.......
CODE
Private Sub cmdTrackATP_Click()
Dim strFilter As String
strFilter = "ATPCheck = True "
strFilter = strFilter & "AND PreCheck = False "
strFilter = strFilter & "AND A5Check = False "
strFilter = strFilter & "AND SorCheck = False "
strFilter = strFilter & "AND DownCheck = False "
strFilter = strFilter & "AND BackCheck = False "
strFilter = strFilter & "AND Sor2Check = False "
strFilter = strFilter & "AND FQACheck = False "
strFilter = strFilter & "AND CompleteCheck = False"
Me.Filter = strFilter
Me.FilterOn = True
vtd
When you want to use the Filter Property of the Form, you should use the Field names of the Fields in the underlying RecordSource, not Control names.
If ATPCheck, PreCheck, A5Check, ... are Field names in the RecordSource of the Form, try something like:
CODE
Private Sub cmdTrackATP_Click()
  Me.Filter = "(ATPCheck = True)" _
    " And (PreCheck = False)" _
    " And (A5Check = False)"     ' add more as appropriate  
  Me.FilterOn = True
End Sub
Alan_G
Hi Van
sn't that what I posted (albeit eventually - it is 4.30am UK time LOL)...........
kidmon
van ur code i have try and it give a compile error and the whole thing goes red
vtd
Yep... I think I took too long to type my post and somehow I never saw the post which the similar filter String.
vtd
Please post your latest code...
kidmon
this is the one i use from yours
Private Sub cmdTrackATP_Click()
Me.Filter = "(ATPCheck = True)" _
" And (PreCheck = False)" _
" And (A5Check = False)" _
" And (SorCheck = False)" _
" And (DownCheck = False)" _
" And (BackCheck = False)" _
" And (Sor2Check = False)" _
" And (FQACheck = False)" _
" And (CompleteCheck= False)" _
Me.FilterOn = True
End Sub
vtd
Sorry, my mistake. Should be:
CODE
Private Sub cmdTrackATP_Click()
  Me.Filter = "(ATPCheck = True)" & _
    " And (PreCheck = False)" & _
    " And (A5Check = False)" & _
    " And (SorCheck = False)" & _
    " And (DownCheck = False)" & _
    " And (BackCheck = False)" & _
    " And (Sor2Check = False)" & _
    " And (FQACheck = False)" & _
    " And (CompleteCheck = False)"
  Me.FilterOn = True
End Sub
kidmon
still cant work
when i click on the command button it request me to enter parameter value for each one
vtd
Are they Fields in the RecordSource of the Form?
kidmon
ya there are and this are the yes and no check box
vtd
Then the latest Filter I posted should be correct. What are the problems when you run the code?
Please post a copy of your database also (compact & zip to less than 500 KB).
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.