As Clifford said, it depends on the keys; if the table of customer
interactions has a single column primary key, with my method you'd correlate
the subquery with the outer query on whatever column is the subreport's
table's foreign key referencing your customers table's primary key; with
Clifford's it will work whether the key is a single column or multiple
columns as you'd reference whatever control or controls in the parent report
are bound to its primary key column or columns.
If you can post back with details of the structure of the table of customer
interactions and which columns you want in the subreport we could probably be
more specific in our replies.
There is another method, which is to design the subreport so that it would
normally list all interactions per customer in date descending order and link
it to the parent report in the normal way, but group the subreport by
CustomerID (or whatever the linking column is named), giving it a group
header. The header can be empty and of zero height if you don't need to show
anything in it. Then in the subreport's module declare a module-level
variable of integer data type, initialize it to zero in the group header's
Format event procedure, and increment it by 1 in the detail section's Format
event procedure, setting the return value of the Cancel argument to True when
the value of the variable passes the number of rows you wish to return in
each instance of the subreport. So, to limit the subreport to 3 rows per
customer, the subreport's module would look something like this:
Option Compare Database
Option Explicit
Dim intCounter As Integer
Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
intCounter = 0
End Sub
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
intCounter = intCounter + 1
Cancel = (intCounter > 3)
End Sub
Ken Sheridan
Stafford, England
Matt said:
Thanks Ken, and Thanks Cliff.
Cliff - now you understand the question, the actual application I am
applying this to is a customer record system with interaction records. We
keep track of every phone call (in and out) and also emails etc - so when we
print out a customer records for our salesmen, they get a history of all the
interactions we have had with that customer. Problem is the list is getting
pretty big so that why I want to limit it to the last 3 or 5 interactions. I
could send you a copy of the file if you could create that sub report for me
- I can't get my head around it. Not sure how to safely get your email
address if this is what you want to do.
I'm using Access 2007 - does this change the information you have given me?
It seems the querie builder is a bit different in this later version.
Thanks again.
[quoted text clipped - 28 lines]