473,408 Members | 1,845 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,408 software developers and data experts.

Print Report for each Filtered Record

Brilstern
208 100+
Ok,

I have a report that is opened up with a filter to a certain person's Equipment Custody Receipt card(ECR). Within this report are two subreports that are linked to the master field on the report to filter each subreport. I can open this report up and print it individually using a form based parameter. What I want to do is print a report for each person or [SSN] on my master table with each persons info. See the link below for the question leading to this one.

http://bytes.com/topic/access/answer...subreport-load

This is what opens up the report:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdOpenECR_Click()
  2.  
  3.    Dim strFilter As String
  4.    strFilter = "[SSN] = '" & Me.MemberSelect & "'"
  5.        Call DoCmd.OpenReport(ReportName:="rptECR", View:=Access.AcView.acViewReport, wherecondition:=strFilter)
  6.  
  7. End Sub
These are the main controls on the Master Report:

Expand|Select|Wrap|Line Numbers
  1.       =[rank] & " " & [lname] & ", " & [fname] & " " & [mi] & "."
  2.     ="XXX-XX-" & Right([ssn],4) & "/" & [MOS]
  3.     =[EAS] & "    Section: " & [Instrument]
  4.     Date Checked In
  5.     SSN (not visible, used for filter)
This is the table that I want to print a report for each [SSN]/This is also the Master Reports datasource:
qryBand Members
Expand|Select|Wrap|Line Numbers
  1.     Field                      Type
  2.     Rank                       Text
  3.     FName                      Text
  4.     LName                      Text
  5.     MI                         Text
  6.     SSN                        Text PK
  7.     MOS                        Text
  8.     EAS                        Date/Time
  9.     Instrument                 Text
  10.     Date Checked In            Date/Time
  11.     Supply Rep                 Text
Location Expression:(=[rank] & " " & [lname] & ", " & [fname] & " " & [mi] & ".")[/code]

Below are the two datasources for the SubReports:
tblInstruments
Expand|Select|Wrap|Line Numbers
  1.     Field                      Type
  2.     Category                   Text
  3.     Instrument                 Text
  4.     Make                       Text
  5.     Model                      Text
  6.     Serial                     Text PK
  7.     Condition                  Text
  8.     Location                   Text (not visible)
  9.     Checked In/Out             Text
  10.     Date Checked Out/In        Date/Time
  11.     Supply Rep Doing Check Out Text
  12.     Purchase Year              Date/Time
tblNon Serialized Gear
Expand|Select|Wrap|Line Numbers
  1.     Field                      Type
  2.     Category                   Text
  3.     Item Name                  Text
  4.     Brand                      Text
  5.     Condition                  Text
  6.     Checked Out                Text
  7.     Location                   Text(not visible)
  8.     Date Checked Out           Date/Time
  9.     Supply Rep Doing Check Out Text
  10.     Description                Text
The Location is the Master/Child Field that creates the filter on the SubReports. The location on both subreports is a built query with the matching expression:

Expand|Select|Wrap|Line Numbers
  1. Expression:(=[rank] & " " & [lname] & ", " & [fname] & " " & [mi] & ".")
Any guidance, I have looked at a lot of forums and none of them seem to lead me any closer to my answer...

Thx
Sgt B
Jan 28 '12 #1

✓ answered by sierra7

I think it is working properly now. By putting the data in the Page Header you were getting the codes for the first record only and this was not changing on subsequent pages.

Each persons Location code must appear in the Detail section to associate the details for that individual. I've just remembered that I have not hidden the Location field but really you could use this instead of your 'member' control.

Note the position of the Page Break, just after the second sub-report.

I've also changed the [Print All] button's code to Print Preview for testing purposes.
S7

28 2963
NeoPa
32,556 Expert Mod 16PB
If I understand you correctly then all you need to do is to remove the WhereCondition parameter from your DoCmd.OpenReport() call (Line #5 from your first code block) :
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.OpenReport(ReportName:="rptECR", View:=acViewReport)
PS. Notice the usual version of the View parameter.
Jan 28 '12 #2
Brilstern
208 100+
NeoPa,

Ok so what this does is it prints one report with half of the data coming from one social and the rest coming from another. Not sure what causes that.

My goal here is to print out separate reports (on different sheets) for each person.

Im my head I see it like this...

For each SSN in [SSN] print out an individual report
Jan 28 '12 #3
NeoPa
32,556 Expert Mod 16PB
The filtering (WhereCondition parameter) determines which data (records) should be included in the report. How the report deals with each record individually is down to the report's design.
Jan 28 '12 #4
Brilstern
208 100+
OK, I understand what you are saying. I think I might be confusing myself here. I do want to filter it. But I want to filter it for each member and then print for each member separately.

Sgt B
Jan 28 '12 #5
NeoPa
32,556 Expert Mod 16PB
In that case (if you're sure - I suspect you could handle it differently mind) you would loop through the various records in your code and open the report to print for each one using the specific filter (for the record currently active).
Jan 28 '12 #6
Brilstern
208 100+
OK, This is more where I was heading, I don't really have much experience with the loop function but I will do some research and ask more if i run into trouble. Thank you for the help.

Sgt B
Jan 28 '12 #7
Brilstern
208 100+
Well this is what I tried and to no luck. I get "data type mismatch in criteria expression" error.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdPrintAll_Click()
  2.  
  3. Dim rsDat As Recordset
  4. Set rsDat = CurrentDb.OpenRecordset("Select [SSN] From [tblBand Members]")
  5. Do
  6.         DoCmd.OpenReport "rptECR", acViewNormal, , "SSN = " & rsDat(0)
  7.  
  8. rsDat.MoveNext
  9. Loop Until rsDat.EOF
  10.  
  11. End Sub
Any Ideas

The below link is where I based my vba off of.
< Snip >

Sgt B
Jan 29 '12 #8
NeoPa
32,556 Expert Mod 16PB
Stevan Bias:
This is more where I was heading
Unsurprising and quite usual thinking. Generally however, not sensible thinking. Without knowing your situation in detail I can only say that a more appropriate approach is probably to design the report to print all the records properly. After all, why design something to ensure only the selected item is included, just so that you can loop through all the items and print them separately? Considering the original report, without the added restriction, does the whole job for you anyway.

Nevertheless, if that's the way you choose to go, and let's face it if you do it the other way there's little more to add is it's far simpler to start with, then your line #4 can be a table rather than the SQL string you've used. Anyway, the following might work for you if my guesses as to what is what are correct :
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdPrintAll_Click()
  2.     Dim cdb As DAO.Database
  3.  
  4.     Set cdb = CurrentDb
  5.     With cdb.TableDefs("[tblBand Members]").OpenRecordset(dbOpenTable)
  6.     Do (While Not .BOF) And (Not .EOF)
  7.         Call DoCmd.OpenReport(ReportName:="rptECR", _
  8.                               View:=acViewNormal, _
  9.                               WhereCondition:="[SSN] = '" & !SSN & "'")
  10.         Call .MoveNext
  11.     Loop
  12. End Sub
PS. This is still not a way I would recommend, but you may have reasons of your why this is your preference so I'll leave it with you.
Jan 30 '12 #9
Brilstern
208 100+
NeoPa,

This does work but what would you suggest. This is my first attempt on "record looping" so I would like to know whats out there.

Sgt B
Jan 30 '12 #10
sierra7
446 Expert 256MB
Hi
From something I remember about a previous post from Stevan, he had over 50,000 people on his database so I can understand that he does not want a report for everyone, just 'Members of the Band', so looping through them as per NeoPa's code should do the trick.

The alternative (more usual) way, would be to setup a new query for the report that included the field that identifies a person as being the member of a band. (while you are at it include any other fields that you may require to filter on i.e Marksmen, Tank driver etc) By then calling this report with the 'WHERE' filter as 'BandMember= True', you should get what you want.

At the foot of each section you will have to include a PAGE BREAK control to ensure each starts on a new page.

If the Quartermaster then wants his tanks back, you are in a position to run an alternative report for just Tank Drivers.
S7
Jan 30 '12 #11
Brilstern
208 100+
Sierra7,

Interesting link to my previous questions but fortunately these are two different databases. In the one in question it only had band members and I want to print a report for every member no matter what. The reason behind the filter is to push the correct information to each report because it has subreports that are filtered.

Sgt B
Jan 30 '12 #12
sierra7
446 Expert 256MB
Hi,
In that case I cannot see why NeoPa's first post did not work.

I imagine both your sub-reports are in the same Detail section ?

If you make a copy of the Master report, then delete the two sub-reports does it run properly.

If you then put in the PAGE BREAK do you then get one page per person?

Then add back one sub-report at a time and re-test. What results?
S7
Jan 30 '12 #13
NeoPa
32,556 Expert Mod 16PB
I'm not clear what you're unclear on Stevan.

S7 describes it reasonably well. The WhereCondition parameter which is used to specify which group, or individual, records to open (and therefore print) controls which to include in the specified print run. If the design of the report handles multiple records properly (Headers and footers in the right places and pages thrown between records where required) then they can all be processed in a single print run.

If you have a table with three records, A; B; C, then you can either say Run report or alternatively, Run report specifically for A, Run report specifically for B and Run report specifically for C. Both approaches eventually produce the same results, but the first is more straightforward.

Does that make sense? Is that what wasn't clear?
Jan 30 '12 #14
Brilstern
208 100+
Here seeing what I may have might help

Because the filter for the report is not in the report itself but pushed via the command to open it, see the attached DB to better explain what it is.

Sgt B
Attached Files
File Type: zip Band Inventory Database 03.zip (2.95 MB, 104 views)
Jan 30 '12 #15
Brilstern
208 100+
I do see what y'all are saying now but I don't know why it wont work.

Sgt B
Jan 30 '12 #16
sierra7
446 Expert 256MB
Hi
A quick look shows that the two subreports are linked to the main report via 'Location'. (Link Master Fields / Link Child Fields)
Surely it should be SSN?

S7
Jan 30 '12 #17
Brilstern
208 100+
Sierra7,

No, If you look on the hidden tables on the instrument and non serialized gear the linking field is location. When the user selects where the item is they don't use SSN because that would just be impracticable. So I have created an expression (location) that uses the Rank, LName, and FName as a combolist selection.

Sgt B
Jan 30 '12 #18
sierra7
446 Expert 256MB
OK
But I could not see a Location in the Master Record. I take it that Rank, LName, and FName are all there but in that case you have to specify them as
Expand|Select|Wrap|Line Numbers
  1. Rank;LName;FName 
for both Mastcer and child fields, or create a 'Location' field in the same format as you used previously.

I'll take a closer look

S7
Jan 30 '12 #19
sierra7
446 Expert 256MB
OK, there are a number of issues.
The first is that although you are formulating and selecting a Location for the Master Record, it's not appearing anywhere on the report and all the other master data is appearing in the Page Header section.

It would be better to move all this heading into the Detail section. I'm still playing.

I also noticed that in the NonSerialized subreport the hidden Location field is in the Page Header, not the detailed section (this may not matter butI'll check)

I have it running OK but I'll put the Page Breaks in and add a few more bods.

S7
Jan 30 '12 #20
sierra7
446 Expert 256MB
I think it is working properly now. By putting the data in the Page Header you were getting the codes for the first record only and this was not changing on subsequent pages.

Each persons Location code must appear in the Detail section to associate the details for that individual. I've just remembered that I have not hidden the Location field but really you could use this instead of your 'member' control.

Note the position of the Page Break, just after the second sub-report.

I've also changed the [Print All] button's code to Print Preview for testing purposes.
S7
Attached Files
File Type: zip Band Inventory Database 04.zip (2.79 MB, 85 views)
Jan 30 '12 #21
Brilstern
208 100+
AHA,

Thank you. I see now, Good to know I'm not completely crazy. Out of curiosity why does the location of the data matter in the since of this report?

Sgt B
Jan 30 '12 #22
NeoPa
32,556 Expert Mod 16PB
Stevan Bias:
Out of curiosity why does the location of the data matter in the case of this report?
Typically, a page header and footer will only reflect data that is common to all sections printed on that page. If there is data that needs to be shown once only for any grouping then group header and footers can be used for that.
Jan 30 '12 #23
Brilstern
208 100+
OK,
I figured that is what it might be but I wanted to make sure. Thx

Sgt B
Jan 30 '12 #24
sierra7
446 Expert 256MB
Hi,
I'd like to gently point out that it was not NeoPa's suggestion that fixed the report, otherwise the issue would have been resolved last week.

What was wrong were the location of field controls in the Header section rather tah the Detail section.
S7
Jan 30 '12 #25
NeoPa
32,556 Expert Mod 16PB
Go ahead and reallocate the Best Answer Stevan. I'm aware you've struggled manfully to decide between the two of us already (I noticed the posts being set and reset over a period). S7 certainly spent some time and effort on assisting you directly with your project. It's hard not to see an answer being reset as a criticism of your work - even though that's often not an accurate reflection of the OP's thinking at all. You, as an OP, are left in a difficult position in a question like this, where you feel more than one member has been particularly helpful in a thread.

I understand all these issues and won't be the least put-out if you use this to thank S7 for his good work in helping you on this issue :-)
Jan 30 '12 #26
Brilstern
208 100+
I understand both of you and yes, I have had a lot of trouble deciding which is better, one because NeoPa's shows the correct code and easier to see the answer but I do see where S7's explanation is more useful to the viewer.
Jan 30 '12 #27
sierra7
446 Expert 256MB
@NeoPa
I'm not really miffed. However, this should have been (forgive me Stevan) a trivially easy question which the first post should have cleared up. (Most usually people create a report then ask the question how to restict it to a selection!)

Anyone searching the database for advice might overlook some of the issues revealed by this case. (If I really wanted to rant, I would pick on the search engine used on this site. I can't even find my own answers to save typing on occasions)

The looping solution is good and may prove useful, especially for producing separate PDF reports for emailing (rather than one long one). It would have been a solution in this case because the content was the same as the header.

However, the posting of the demo database was invaluable in helping to resolve this issue. Thanks for taking the time to prepare it Stevan; I know how much time it takes to sanitize data. I think we should ask for samples more frequently because so much time is taken trying to decide what the OP means and we can easily end-up making wrong assumptions.

I'm just an occasional visitor to the site and am not looking for Brownie Points, just answers.
S7
Jan 30 '12 #28
NeoPa
32,556 Expert Mod 16PB
S7:
I think we should ask for samples more frequently because so much time is taken trying to decide what the OP means and we can easily end-up making wrong assumptions.
I know exactly where you're coming from S7. I prefer to encourage posters to express their questions clearly, however, rather than to take the easy way out (for most) and decide that the experts can dig around for themselves to work out what the question should have been.

It's always going to be a problem, as very few people generally are skilled in the use of language nowadays. Fewer even appreciate why it can be important. Clearly anyone spending as much time as you do (Occasioinal Visitor is a bit too modest.) gets to realise very early on how important it can be when you see so many threads where the answers would be so obvious if only the questions were asked properly (@Stevan - I'm talking generally here. In no way is this directed at you).

PS. As a starter, [site:bytes.com sierra7 XXX] in Google will help you find your XXX posts.
PPS. I just added a quick feedback mini-article to help with this issue - Searching For Answers Within a Specific Site (EG. Bytes.com).
I use a database for all the important threads myself. Let me know if you'd like a copy.
Jan 30 '12 #29

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

Similar topics

2
by: Dmitry | last post by:
Hello everyone, I have a really simple question here: I have a plain space delimited file that I want to read with WHILE loop 1 line at the time and process each input record as an array of...
9
by: David Allison | last post by:
cmdButton to Print 3 copies of record in Form view ? cmdButton will print 1 but I need 3 copies of the one Form record. -- Dave Allison
2
by: Lapchien | last post by:
I've had a look on usenet but cannot find exactly what I want - and it should be simple enough i guess..? I have a purchase order database, nothing complicated, just a form based on 2 or 3...
1
by: Nothing | last post by:
Question: I have a form, open to a record, displaying some information. I have a button, on the form, that I want to click and have a print funtion on it. I want it to print the current record to...
5
by: Tony Dong | last post by:
Hi there, I am newer for dot net I want to make a report and then print it, the report may include images and text, how can I do that, any one can give me a suggestion? I know how to...
4
by: JHite | last post by:
I have constructed a report which show lists (from tables). When I print the report, each list has a box border with top and left sides a thin black line and the right and bottom sides a thin gray...
1
by: thh108688 | last post by:
Hi All, Is anyone know how to do a print report based on my current record. What i would like to get is once i have entered all the value in the form, when i hit the print button, all the value...
7
by: KiwiGenie | last post by:
I have a form which lists selected records, there could be anything from 1 record to all records selected. I want to output a report for each record as HTML. I want each file to take its name from a...
1
by: abil | last post by:
i've already build a program that contain all the price, the change given back to the customer but i dun have no idea which function i should use to do program print report... #include <cstdlib>...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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
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...

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.