473,507 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filter Criteria in a Report

2 New Member
I am trying to display the "Filter by Form" criteria in a Report (that displays the filtered information). I have an unbound textbox with [Forms]![RosterForm].[Filter] as the control source that will give me the Filter itself but I need to clean this up. I envisioned a listing in the header of the report that would list each of the categories (there are six) and the filter criteria specified for the category.

This is a demographics database application for a Fire Department. My criteria are Sex (Male, Female), Race (American Indian/Alaska Native, Asian, Black/African-American, Hispanic, White/Caucasian, Other), Rank (Chief, Deputy Chief, Battalion Chief, Captain, Master Firefighter, Firefighter, Civilian), Paramedic Status (Paramedic, Non-Paramedic), and Assignment(Operations, Administration).

I wanted to have labels in the header and the filter criteria for each category. For example:

Assignment: Operations
Assignment: Administration
Assignment: Operations & Administration
Assignment: Not Specified

Can this be done? This is an example of my filter string:

((([Roster Query].Rank)="3") AND (([Roster Query].Assignment)="1") AND (([Roster Query].Sex)="1") AND (([Roster Query].Paramedic)="1") AND (([Roster Query].Race)="6")) OR ((([Roster Query].Sex)="2"))
Nov 22 '06 #1
2 2346
tjdoss
2 New Member
Actually, for the string that I provided, the header would appear like this:

Rank: Battalion Chief
Sex: Male
Paramedic Status: Paramedic
Race: White/Caucasian
Sex: Male

((([Roster Query].Rank)="3") AND (([Roster Query].Assignment)="1") AND (([Roster Query].Sex)="1") AND (([Roster Query].Paramedic)="1") AND (([Roster Query].Race)="6")) OR ((([Roster Query].Sex)="2"))[/quote]
Nov 22 '06 #2
NeoPa
32,557 Recognized Expert Moderator MVP
In fact, yes there is.
I will copy in an example of something I've done along those lines.
Bear in mind, this was not designed for your purpose and is only included to prompt you with ideas of some of the things that can be done.

Bear in mind that setting the report's RecordSource property will cause the underlying dataset to be re-calculated.
The help system should explain which properties are available to you.

Above all, don't be daunted by the length of the code sample, it has various concepts within but you're not likely to need all. Treat it as a 'reference library'. Also bear in mind some of the code may refer to items (procedures, tables, etc)which are not available to you.
[code]'On Open, this report determines the state of the form and adjusts various
'things based on that. If form not found then it defaults to showing :
' Main Stock Products only
' Costs
' Opal Column Prices
' Sorting must be handled by multiple reports.
Private Sub Report_Open(Cancel As Integer)
Dim intSort As Integer, intSelRange As Integer, intPCs As Integer
Dim intSpare As Integer
Dim strSort As String, strWork As String, strType As String
Dim strPC1 As String, strPC2 As String
Dim blnReplacement As Boolean, blnCosts As Boolean, blnVisible As Boolean

On Error Resume Next
'If next line fails then intFrom stays 0 - otherwise it will be > 0
intFrom = Forms("frm" & conStub).fraFrom
On Error GoTo 0
intPCs = 0
If intFrom = 0 Then
'Form not found
intSelRange = 1
blnReplacement = True
blnCosts = True
intSort = 2
strSort = "Prod Group then Desc"
intFrom = 3
intPCs = 1
dblPC1 = 100 / 60 '40% GPM
Else
'Form found - use settings from form
With Forms("frm" & conStub)
intSelRange = IIf(.chkMainStock, 1, 0) + IIf(.chkLawForms, 2, 0)
blnReplacement = .chkReplacement
blnCosts = .chkShowCost
intSort = .fraSort
Select Case intSort
Case 1
strSort = .lblPGrpCode.Caption
Case 2
strSort = .lblPGrpDesc.Caption
Case 3
strSort = .lblProdCode.Caption
Case 4
strSort = .lblProdDesc.Caption
End Select
If intFrom > 1 Then
intPCs = 1
strPC1 = Nz(.txtPC1, "")
dblPC1 = IIf(intFrom = 2, (100 + CDbl(strPC1)) / 100, _
100 / (100 - CDbl(strPC1)))
strPC2 = Nz(.txtPC2, "")
dblPC2 = CDbl(0)
If strPC2 > "" Then
intPCs = 2
dblPC2 = IIf(intFrom = 2, (100 + CDbl(strPC2)) / 100, _
100 / (100 - CDbl(strPC2)))
End If
End If
End With
End If
'Set up Sorting & Grouping
'Only show PGroupHdr if sorting primarily by PGroup and turn triggering
'to as few as possible (using Prefix) if not showing (otherwise Each)
'Assume both levels must be set with different fields regardless
PGroupHdr.Visible = (intSort < 3)
'.GroupOn ==> 0 = Each; 1 = Prefix
GroupLevel(0).GroupOn = IIf(intSort < 3, 0, 1)
Select Case intSort
Case 1
GroupLevel(0).ControlSource = "PGroup"
GroupLevel(1).ControlSource = "Product"
Case 1
GroupLevel(0).ControlSource = "PGroup"
GroupLevel(1).ControlSource = "ProdDesc"
Case 3
GroupLevel(0).ControlSource = "Product"
GroupLevel(1).ControlSource = "PGroup"
Case 4
GroupLevel(0).ControlSource = "ProdDesc"
GroupLevel(1).ControlSource = "PGroup"
End Select
With txtTitle
Select Case intFrom
Case 1
strType = "Columns"
Case 2
strType = "Markups"
Case 3
strType = "GPMs"
End Select
.ControlSource = ParamReplace(.ControlSource, "%S", strSort, _
"%T", strType)
End With
If intSelRange = 3 Then
FilterOn = False
Else
FilterOn = True
strWork = Split(Expression:=conFilters, Delimiter:="|")(intSelRange - 1)
Filter = ParamReplace(strWork, "%L", conLawForms)
End If
lblCost.Visible = blnCosts
txtCost.Visible = blnCosts
'Adjust widths and visibilities of various fields
'Some field attribute may need to be adjusted from their starting values
'ProdDesc.Width = 7.354cm (4,170) conDescWidth
'Unit.Width = 1.24cm (703) conUnitWidth
'PriceFields.Width = 1.199cm (680) conPriceWidth
'Expand width of Description if either Columns OR Cost not shown
lblProdDesc.Width = _
conDescWidth + IIf(intFrom > 1 Or Not blnCosts, lblCost.Width, 0)
'Set basic widths for Price Columns 1 - 2
lblPrice1.Width = conPriceWidth
lblPrice2.Width = conPriceWidth
'Set captions, width and visibility for Column fields used
If intPCs < 1 Then
lblPrice2.Caption = ParamReplace(conColLbl, "%N", 2)
lblPrice3.Caption = ParamReplace(conColLbl, "%N", 3)
txtPrice2.ControlSource = "Price2"
txtPrice3.ControlSource = "Price3"
Else
strWork = strType & vbCrLf
lblPrice2.Caption = strWork & strPC1 & "%"
txtPrice2.ControlSource = "=Round([Cost]*" & dblPC1 & ",2)"
lblPrice3.Caption = strWork & strPC2 & "%"
txtPrice3.ControlSource = "=Round([Cost]*" & dblPC2 & ",2)"
End If
lblPrice3.Visible = (intPCs > 1)
'Special handling for new style report (chkReplacement = True)
If blnReplacement Then
lblPrice2.Caption = ParamReplace("Min Sell%L%N%", "%N", strPC1, _
"%L", vbCrLf)
lblReplacement.Visible = True
End If
'Handle last 3 column fields (Only leave required fields visible)
blnVisible = (intFrom = 1)
lblPrice4.Visible = blnVisible
lblPrice5.Visible = blnVisible
lblPrice6.Visible = blnVisible
txtPrice4.Visible = blnVisible
txtPrice5.Visible = blnVisible
txtPrice6.Visible = blnVisible
'Build up positions and mirror widths & visibilities
intSpare = (Width - BuildUp() - 10) / 4
If intFrom > 1 And intSpare > 25 Then
If intSpare > conExtend Then intSpare = conExtend
lblUnit.Width = conUnitWidth + intSpare
lblCost.Width = conPriceWidth + intSpare
lblPrice1.Width = conPriceWidth + intSpare
lblPrice2.Width = conPriceWidth + intSpare
Call BuildUp
End If
'Set up Report ID & date for bottom left corner of report
strDate = DLookup(Expr:="
Expand|Select|Wrap|Line Numbers
  1. ", _
  2.                       Domain:="[tblReport]", _
  3.                       Criteria:="[ReportName]='" & Name & "'") & _
  4.                                 Format(Date, " - d mmmm yyyy")
  5. End Sub
Nov 22 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
6454
by: CSDunn | last post by:
Hello, I have a problem with field filtering between an Access 2000 Project form (the application is called CELDT), and the report that shows the results of the filter. Both the form and the...
3
2892
by: Afton | last post by:
I would like to make a form that filters a report by Supervisor and by starting and ending date. I have the supervisors in a combo box, and that works. However, I do not know how to code to let...
2
2476
by: Mike Sweetman | last post by:
I have a form Form1 which when the Advanced Filter/Sort is used creates a form(maybe) with a title 'Form1Filter1 : Filter'. When I apply the filter to Form1 it is applied, but the value of...
4
5116
by: Nhmiller | last post by:
This is directly from Access' Help: "About designing a query When you open a query in Design view, or open a form, report, or datasheet and show the Advanced Filter/Sort window (Advanced...
1
16357
by: lorirobn | last post by:
Hi, I have a report that works just fine. Now I would like to add the capability to choose selection criteria to limit what is displayed. I created several reports that do this, but they used...
7
2346
by: fleece | last post by:
I set up a form for searching criteria and pass the searching result to a report. On this report there is an unbound text box (=.Filter) and shows the searching criteria. It works fine when searching...
1
5610
by: Cara Murphy | last post by:
Hi There! Hoping you are able to help me with a filtering scenario: I have created a pop up form (Filter) to filter a report (Open Issues), which currently has a number of combo boxes which...
4
4498
by: Fran | last post by:
I recently tried to use code for "Use a multi-select list box to filter a report" from Allen Browne in my database. I was able to add the code and adapt it to my needs, however I am getting an...
5
4002
by: DAHMB | last post by:
Hi all, Using Access 2007 I have a report called Sunday School Attendance based on a Query called qryAttendance the query is as follows: SELECT tblSundaySchoolAttendance.StudentID,...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.