Filter a subform

R

Ryan Tisserand

Access 2003
Windows Vista Business

Form Name - C25Transactions
Subform Name - C25Transactions subform
Filter Name - Filter
Filter Field Name - CheckFilter

When I click the filter button on the main form I want to filter the data on
the subform by the Check# Field. Here is my current code that I cant seem to
get to work. Please help by correcting my code.

Private Sub Filter_Click()
Dim strWhere As String
Dim lngLen As Long


If Not IsNull(Me.CheckFilter) Then
strWhere = strWhere & "(Me![C25Transactions_subform].Form![Check#]= " &
Me.CheckFilter & ") AND "
End If

lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "Please enter at least one Search Criteria", vbInformation,
"Nothing to do."
Else
strWhere = Left$(strWhere, lngLen)
Debug.Print strWhere


Me.C25Transactions_subform.Form.Filter = strWhere
Me.C25Transactions_subform.Form.Filter = True
End If

Me.C25Transactions_subform.Form.Filter = strWhere
Me.C25Transactions_subform.Form.Filter = True

End Sub
 
H

Hajo von Kracht

Great question. I am struggling with the exact same issue. Hope someone can
help.
 
R

Ron2006

Great question. I am struggling with the exact same issue. Hope someone can
help.

Have you tried issuing the following after you have set the filter?

Me.C25Transactions_subform.requery


Ron
 
R

Ron2006

Have you tried issuing the following after you have set the filter?

Me.C25Transactions_subform.requery

Ron

And probably more to the point it should probably be

Me.C25Transactions_subform.Form.FilterOn = True

and not
Me.C25Transactions_subform.Form.Filter = True
with this instruction you have just made the filter value
true (-1)


Ron
 
R

Ryan Tisserand

I solved my own problem. Here is the solution.
Private Sub Filter_Click()
Dim strWhere As String
Dim lngLen As Long
Const conJetDate = "\#mm\/dd\/yyyy\#"


If Not IsNull(Me.CheckFilter) Then
strWhere = strWhere & "([Check#]= " & Me.CheckFilter & ") AND "
End If
If Not IsNull(Me.PaymentFilter) Then
strWhere = strWhere & "([Payment]= " & Me.PaymentFilter & ") AND "
End If

lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "Enter at least one Search Criteria", vbInformation, "Nothing
to do."
Else
strWhere = Left$(strWhere, lngLen)
Debug.Print strWhere


C25Transaction_subform.Form.Filter = strWhere
C25Transaction_subform.Form.FilterOn = True
End If

C25Transaction_subform.Form.Filter = strWhere
C25Transaction_subform.Form.FilterOn = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top