473,382 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

applying filter from form on report

k
Hi
I have a form which the user can apply filters, and push a button to
preview a report. I cannot use me.filter=forms!myform.filter, because
some of the filtered fields are not present in the report. What I would
like is to obtain the ID field from the filtered form, and show only
those ID's in the report.

K

Nov 13 '05 #1
5 2761
k wrote:
Hi
I have a form which the user can apply filters, and push a button to
preview a report. I cannot use me.filter=forms!myform.filter, because
some of the filtered fields are not present in the report. What I would
like is to obtain the ID field from the filtered form, and show only
those ID's in the report.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You'll have to get a comma delimited list of the IDs from the form's
Recordset and pass them to the report in the WhereCondition parameter.
E.g. (this assumes you're using DAO):

' get the list of IDs from the form's Recordset
Dim strIDs As String
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
Do While Not rs.EOF
strIDs = strIDs & rs!ID & ","
rs.MoveNext
Loop
' get rid of trailing comma
If Len(strIDs) > 0 Then strIDs = Left$(strIDs, Len(strIDs)-1)
' Open report w/ IDs
DoCmd.OpenReport "myReport", WhereCondition:="ID In (" & strIDs & ")"

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQi9U0YechKqOuFEgEQKJswCgpGUlG9IFSqnhTjsFSena94 eXhtgAoPjm
XO8PhqGPV2bk2ZKqkHmRQbpS
=jTnu
-----END PGP SIGNATURE-----
Nov 13 '05 #2
k
Thanks, that does the trick.

But only the first time I push my button, the second time I push the
button. The variable strIDs is empty, and the condition becomes "ID in
()"

If I change the filter, the button works again, once.

K

Nov 13 '05 #3
k wrote:
Thanks, that does the trick.

But only the first time I push my button, the second time I push the
button. The variable strIDs is empty, and the condition becomes "ID in
()"

If I change the filter, the button works again, once.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In place of this:

Set rs = Me.RecordsetClone
Do While Not rs.EOF

put this:

Set rs = Me.RecordsetClone
on error resume next
rs.movefirst
on error goto err_handler
Do While Not rs.EOF

Put an error handler routine in your Sub to handle the error of "no such
record" when MoveFirst tries to move to a non-existant record (when the
recordset is empty).

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQi99n4echKqOuFEgEQJDigCePQ5XiPqQuik/TwGEinKyicuLTJ8An0sl
nHtPTx/bD0Y1rJoip4pjlxZK
=QJzx
-----END PGP SIGNATURE-----
Nov 13 '05 #4
k
Great! Thanks!

K

Nov 13 '05 #5
k wrote:
Great! Thanks!

K


Alternatively you could replace

DoCmd.OpenReport "myReport", WhereCondition:="ID In (" & strIDs & ")"

in MGFoster's first solution with

If Len(strIDs) > 0 Then
DoCmd.OpenReport "myReport", WhereCondition:="ID In (" & strIDs & ")"
Else
MsgBox("No such record.")
End If

and let the On Error's deal with sterner stuff :-). Note: If you do
this, it would also be good to assign strIDs = "" before the Do While
loop so that strIDs will be assigned a string whether or not the loop
executes.

James A. Fortune

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
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
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...
3
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...
4
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...
4
by: MS | last post by:
I'm having trouble applying a filter to a subform. I create a String in a Module based on various selections on the form. Clicking a button on the "stand alone form" that changes the filter...
1
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...
1
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...
5
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,...
3
by: franc sutherland | last post by:
Hello, I have a report which I filter using the me.filter command in the OnOpen event. Me.Filter = "OrderID=" & Forms!variable_form_name! Me.FilterOn = True I want to be able to open that...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.