Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 14th, 2004, 09:25 AM
Registered User
 
Join Date: Apr 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Combining Records in a Report

I would like to group records from a query together in a line rather than in a table in a report.

I have two tables, one Territory and the other Territory Groups
i.e
Territory
Australia
Argentina
Belgium etc.

and

TerritoryGp
North America
Europe
etc.

They are linked by a Territory Detail table on a 1 to many, many to one basis

I have set up the following query to create the following output
SELECT tblTerritoryGp.cTerritoryGp, tblTerritory.cTerritory
FROM tblTerritory INNER JOIN (tblTerritoryGp INNER JOIN tblTerritoryDetail ON tblTerritoryGp.nTerritoryGpID = tblTerritoryDetail.nTerritoryGpID) ON tblTerritory.nTerritoryID = tblTerritoryDetail.nTerritoryID;

TerritoryGp Territory
North America Canada
North America U.S.A.
North America Mexico
Europe UK
Europe France
Europe Italy etc.

I would however like to express these records in a report as follows:-

North America Canada, U.S.A., Mexico
Europe UK, France, Italy, etc.

How can I combine the territory records per territory group to print out in one text box with commas between them?

Thanks for your help.
 
Old April 14th, 2004, 07:02 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You'll probably be wanting to use a recordset that determines the textbox ro label value when the report is formatted, so you have something like:
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim rst as Recordset
Dim strValues as String
set rst = CurrentDB.OpenRecordSet( _
  "SELECT Territory FROM tblTerritoryDetail WHERE " _
& "TerritoryGp = '" & Me.txtTerritoryGroup & "'")

While Not rst.EOF
  strValues = strValues & ", " & rst("Territory")
  rst.MoveNext
Wend
'Strip off the first ", "
strValues = right(strValues, len(strValues)-2)
Me.lblYourLabel.Caption = strValues
End Sub
Of course, you'll most likely have to change a fair bit of the code, but it should point you in the right direction.
This is NOT a definitive answer, just something off the top of my head. (Thought I should put that disclaimer in lest I be rebuked by Jürgen again)
 :)

Steven

I am a loud man with a very large hat. This means I am in charge





Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying Multiple Records on Report bnc111 Access 1 August 16th, 2007 02:10 PM
Counting 'groups' of records in a report Odeh Naber Access 4 July 30th, 2007 10:41 AM
Linked images in report records bmurrin Access 12 February 11th, 2005 12:59 PM
Double records in a report timoma Access 4 November 14th, 2004 05:25 PM
Combining records OCM Access 2 November 19th, 2003 04:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.