Multiple Filters within vba

jules68

Registered User.
Local time
Tomorrow, 08:23
Joined
Aug 9, 2012
Messages
13
I have a button on a form that runs 1 report, i'm trying to apply a filter for selections made prior to the button being selected. TO allow for many options within the one report.

I have read through many forum pages and can't find exactly what i'm looking for.

I can get one filter to work perfectly. however i would like to add another 1 or 2 parameters to my filtering.

Here is my code for the one filter which works.

Reports!rptFINALByTeam.filter = "FTPT = 'PT'"
Reports!rptFINALByTeam.filteron = true

How do you add another filter? I have tried many different ways and they dont work.

here is one way.

Reports!rptFINALByTeam.filter = "FTPT = 'PT'"
Reports!rptFINALByTeam.filter = "Team = 'Silverchair'"Reports!rptFINALByTeam.filteron = true

When using this code, the Team is filtered but the PT is not, seems the team overrides the FTPT.

Any suggestions are greatly appreciated.

Thanks
 
Your filter will look something like;
Code:
Reports!rptFINALByTeam.filter = "FTPT = 'PT' And Team = 'Silverchair'"
Reports!rptFINALByTeam.filteron = true
 
I think John's reply is in the right direction.

I've recently also have a similar issue as you and I solved it by:
(1) Creating a Public string variable for the filter (call it strFilter)
Code:
Public strFilter as String
(2) Creating a module that will update strFilter depending on the value for different criteria
Code:
Public Function ApplyAllFilters()
' Reset all criteria. 
If Field1StrFilter = "" Then
Field1StrFilter = " TRUE "
End If
If Field2StrFilter = "" Then
Field2StrFilter = " TRUE "
End If
If Field3StrFilter = "" Then
Field3StrFilter = " TRUE "
End If
...
...
...
...

strFilter = Field1StrFilter & " AND " _
                & Field2StrFilter & " AND " _
                & Field3StrFilter 

End Function

(3) Back to your Form, your strFilter will be basically be the sum of different criteria. The criteria can be user-defined through buttons, checkboxes, comboboxes and the like.
So upon Click or AfterUpdate, your different buttons/checkboxes should update the corresponding criteria (ex: Field1StrFilter ).
For example:
Code:
Public Sub ItemAButton_Click()
Field1StrFilter = "[Item] = "A"
End Sub

Of course, you should also update your report's filter every time the Form user triggers a criteria.
Code:
Call MyModule.ApplyAllFilters
Reports!rptFINALByTeam.filter = StrFilter
Reports!rptFINALByTeam.FilterOn = True


Is that what you are trying to do?

Cheer,
T.
 
another way is to have a field in the reports base query, comprising a boolean function with criteria set to TRUE

IncludeThisRecord(parameter1, parameter2, parameter3 ...)

now have a function

function IncludeThisRecord(p1,p2,p3 ....) as boolean
.. code ..
end function

the problem is that this function has to be called for every record in the domain, but then I guess the filter approach is similar also.
 

Users who are viewing this thread

Back
Top Bottom