473,769 Members | 4,202 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

filter report based on filters in form

56 New Member
have a mainform called PendingsMain and a subform called
PendingsSub. You can filter the subform by different filters and this
works fine.

i want to create a report that will print out the results of the users
filters or print everything if there is no filters submitted within
the form.


Any suggestions


This is what i have so far:


Expand|Select|Wrap|Line Numbers
  1. Dim StrWhere As String 
  2. With Me.[FPastDuePendingsSub].Form 
  3.            If Me.FPastDuePendingsSub.Form.FilterOn = True Then 
  4.                 StrWhere = Me.FPastDuePendingsSub.Form.Filter & _ 
  5.         " AND ([opid] = """ & Me.cboopid & """)" 
  6.            End If 
  7.         End With 
  8. DoCmd.OpenReport "RPendDetail", acViewPreview, , StrWhere 

if an "opid" is not selected but another filter is like "ProdCD"
"DateIn", "Policy" it will not filter the report. I need to take in
account all of the filters that could be selected or left null just
not sure how.
May 27 '07 #1
5 2796
ADezii
8,834 Recognized Expert Expert
have a mainform called PendingsMain and a subform called
PendingsSub. You can filter the subform by different filters and this
works fine.

i want to create a report that will print out the results of the users
filters or print everything if there is no filters submitted within
the form.


Any suggestions


This is what i have so far:


Dim StrWhere As String
With Me.[FPastDuePending sSub].Form
If Me.FPastDuePend ingsSub.Form.Fi lterOn = True Then
StrWhere = Me.FPastDuePend ingsSub.Form.Fi lter & _
" AND ([opid] = """ & Me.cboopid & """)"
End If
End With
DoCmd.OpenRepor t "RPendDetai l", acViewPreview, , StrWhere


if an "opid" is not selected but another filter is like "ProdCD"
"DateIn", "Policy" it will not filter the report. I need to take in
account all of the filters that could be selected or left null just
not sure how.
  1. The first thing I did was to tidy up your code a litte since the current syntax defeats the purpose of the With..End With Construct.
  2. I was a little confused by the question, but I think that the following revised code will point you in the right direction.
    Expand|Select|Wrap|Line Numbers
    1. Dim StrWhere As String
    2. With Me.[FPastDuePendingsSub].Form
    3.   If .FilterOn = True Then
    4.     If Not IsNull(Me.cpoopid) Then
    5.       StrWhere = .Filter & " AND ([opid] = """ & Me.cboopid & """)"
    6.     Else
    7.       StrWhere = .Filter
    8.     End If
    9.   End If
    10. End With
    11.  
    12. DoCmd.OpenReport "RPendDetail", acViewPreview, , StrWhere
May 27 '07 #2
NeoPa
32,573 Recognized Expert Moderator MVP
As a full member now, you should know that we expect your code to be posted in [code] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.
Please use the tags in future.

MODERATOR.
May 27 '07 #3
favor08
56 New Member
  1. The first thing I did was to tidy up your code a litte since the current syntax defeats the purpose of the With..End With Construct.
  2. I was a little confused by the question, but I think that the following revised code will point you in the right direction.
    Expand|Select|Wrap|Line Numbers
    1. Dim StrWhere As String
    2. With Me.[FPastDuePendingsSub].Form
    3.   If .FilterOn = True Then
    4.     If Not IsNull(Me.cpoopid) Then
    5.       StrWhere = .Filter & " AND ([opid] = """ & Me.cboopid & """)"
    6.     Else
    7.       StrWhere = .Filter
    8.     End If
    9.   End If
    10. End With
    11.  
    12. DoCmd.OpenReport "RPendDetail", acViewPreview, , StrWhere
so do I continue to add iff then statements for the other filters?
May 27 '07 #4
favor08
56 New Member
Expand|Select|Wrap|Line Numbers
  1. Dim StrWhere As String
  2. With Me.[FPastDuePendingsSub].Form
  3.   If .FilterOn = True Then
  4.     If Not IsNull(Me.CboOpid) Then
  5.       StrWhere = .Filter & " AND ([opid] = """ & Me.CboOpid & """)"
  6.     Else
  7.       StrWhere = .Filter
  8.       End If
  9.       If Not IsNull(Me.cbofilterProd) Then
  10.       StrWhere = .Filter & " AND ([prodcd] = """ & Me.cbofilterProd & """)"
  11.       Else
  12.       StrWhere = .Filter
  13.           End If
  14.           If Not IsNull(Me.cboCmtCd) Then
  15.           StrWhere = .Filter & " And ([excd] = """ & Me.cboCmtCd & """)"
  16.           Else
  17.           StrWhere = .Filter
  18.           End If
  19.    End If
  20. End With
  21.  DoCmd.OpenReport "RPendDetail", acViewPreview, , StrWhere
this is what I have everytime I add a piece of code the previous filter does not work. If no filter is picked the report works and if I pick a excd it works but now the opid and prodcd does not work. If I remoe the excd filter the prodcd will work but not the opid and so on.
May 27 '07 #5
ADezii
8,834 Recognized Expert Expert
Expand|Select|Wrap|Line Numbers
  1. Dim StrWhere As String
  2. With Me.[FPastDuePendingsSub].Form
  3.   If .FilterOn = True Then
  4.     If Not IsNull(Me.CboOpid) Then
  5.       StrWhere = .Filter & " AND ([opid] = """ & Me.CboOpid & """)"
  6.     Else
  7.       StrWhere = .Filter
  8.       End If
  9.       If Not IsNull(Me.cbofilterProd) Then
  10.       StrWhere = .Filter & " AND ([prodcd] = """ & Me.cbofilterProd & """)"
  11.       Else
  12.       StrWhere = .Filter
  13.           End If
  14.           If Not IsNull(Me.cboCmtCd) Then
  15.           StrWhere = .Filter & " And ([excd] = """ & Me.cboCmtCd & """)"
  16.           Else
  17.           StrWhere = .Filter
  18.           End If
  19.    End If
  20. End With
  21.  DoCmd.OpenReport "RPendDetail", acViewPreview, , StrWhere
this is what I have everytime I add a piece of code the previous filter does not work. If no filter is picked the report works and if I pick a excd it works but now the opid and prodcd does not work. If I remoe the excd filter the prodcd will work but not the opid and so on.
The effects of multiple Filters does not seem to be cumulative, e.g. Filter #2 does not work off Filter #1.
You may have to change your strategy:
  1. Declare StrWhere as a Public Variable.
  2. Instead of building a Filter String, build a SQL String using the same StrWhere Variable.
  3. In the Open() Event of your Report set the RecordSource to something similar to:
    Expand|Select|Wrap|Line Numbers
    1. Me.RecordSource = "SELECT * FROM <your table> WHERE " & StrWhere & ";"
May 28 '07 #6

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

Similar topics

0
6476
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 report are based on the same View addressed in the Record Source of both as 'dbo.CLMain_vw'. The View resides in a SQL Server 2000 database. There are two different problems I am having with filtering: The first involves filtering in the form by date...
3
3787
by: Baz'noid | last post by:
Hi all, With the recent postal strikes here in the UK i'm trying to persuade access to email reports at the touch of a button. I've not been able to figure out how to filter the report - when i print a report via a button i have it filtering to just the customer and invoice on the form on screen, but when i email, it uses the customer details on screen for the email address but produces a separate HTML file for EVERY customer on the...
3
6614
by: Richard | last post by:
Hi, I have a form based on a table. When I filter the form I want to run a report based on the same table with the same filter as the form. No problem until I want to filter a combo box where the text value is on a different table. The me.filter is then a text instead of the id-number from the lookup table. This causes the report to prompt for the parameter. How do I get by this problem? Do I need to create a temporary table? I rather...
3
2909
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 the user enter a starting and ending date and only show the records between those dates. The code that I have so far does not work for the dates, but I'm including it anyway so you show me what to change. Thanks so much! :) Here is my code (the...
1
1696
by: tremor | last post by:
I'd like to print a form based on the filters currently applied to it (these are again based on selections in combo-boxes). The form has multiple subforms, and as I try to print it, it prints all records in each of these, not just the ones i have showing based on the filters set. These filters are set in the VB code, as child/master dependencies wouldn't cut it in this case. I'm sort of pressed on time here, so I really don't want to...
1
5637
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 apply the filters to the fields in the report. I would like to use this form to filter the report within a date range (Raised Date From and Raised Date To), using unbound text boxes, without having to specify the criteria within the report's...
2
16683
by: smorrison64 | last post by:
I have a form that is coded to open a File Dialog boc to pick a picture to display on that particular item on a subform. My form is not based on query, but rather two separate tables (one primary, one sub). That code is working properly. How do I get that to translate to my report? I use VBA code because I use formats other than BMP for the pictures. Would basing the form on the qury that the report is based on solve the issue without...
5
4020
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, tblSundaySchoolAttendance.AttendanceDate, . FROM tblSundaySchoolAttendance INNER JOIN ON tblSundaySchoolAttendance.StudentID=.StudentID;
7
2191
by: Xaysana12345 | last post by:
Hello there, I have created number of Buttons on unbound form to filter the report based on a pivot query called filters. Report named AnnualReport-ProjectFilter. What I would like to do is that: 1. When I click a button named btnCT then it should search in a Pivot query where the field named ProjectName = CT then views only all the records related to CT Project in the Report. Now when I click a button name btnCP, it should exhibit...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10219
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.