Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


format access report so that records will run horizontally instead of vertically

Posted on 2010-09-13
Medium Priority
Last Modified: 2012-06-21
Is there any way to format access report so that records will run horizontally instead of vertically?  I am putting together a report which will appear in a book.  Each ancestor has multiple children.  The query behind the report looks like this:
1034      David      Allen      Robert
1034      David      Allen      John
1034      David      Allen      Thomas
1034      David      Allen      David
1034      David      Allen      James Joseph
1034      David      Allen      Mary
1034      David      Allen      Benjamin
1098      Richard      Aycock      Edward
1098      Richard      Aycock      Burwell
1098      Richard      Aycock      Henry
1098      Richard      Aycock      Joel
1098      Richard      Aycock      Rebecca
1098      Richard      Aycock      Richard, Jr.
1098      Richard      Aycock      Winifred "Polly"
1144      Roger      Barton      Hugh
1144      Roger      Barton      Clark Talbot
1144      Roger      Barton      Gilbert
1144      Roger      Barton      Armstead

They want the report to look like this in the book but showing all the children instead of just one:
7100      Abernathy, John Jr,   (PS VA) (c1743 - c1824) Spouses:  m Molly ;  m c1762/65 Mary; Children: Nnancy b c1763
7101      Abernathy, John Sr,   (PS VA) (1723 - 1812) Spouses:  m 1744 Lucy; Children: Frederick b 1745
7102      Abney, Paul,   (Pvt VA) (1755-60 - 1815) Spouses:  m 1785 Rhoda; Children: Thomas b 1785
7103      Adams, Drury,   (Pvt SC) (c1755 - 1814) Spouses:  m Sarah;  m Elizabeth; Children: Mary
7104      Adamson, Basil,   (Pvt/PS MD) (1728 - 1785) Spouses:  m 1747 Nancy; Children: John

I need a way to get the children records in the report to run across the page instead of the default vertical orientation.
If this is impossible, then is there a way to format a query to help make this possible.
Question by:ksilvoso
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 20

Expert Comment

ID: 33662035
No.  You'll have to create a temp table with one long text field and then code to populate.

Scott C

Author Comment

ID: 33662068
For further clarification, this is how the report looks now:

Monday, September 13, 2010      0.362708333            
1034      David      Allen      
                  James Joseph
1098      Richard      Aycock      
                  Richard, Jr.
                  Winifred "Polly"
1144      Roger      Barton      
                  Clark Talbot
LVL 58
ID: 33662263
No need for a temp table, just some code in the report.  Have you written any code before?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 58
ID: 33662279
BTW, I should have added that without resorting to code in some way, you can't do what you want with the built-in tools.  A cross tab query comes closest to what you need, but even that doesn't quite fit the bill.

Author Comment

ID: 33662566
I have copied and tweaked code.  Could anyone give me a code example?
LVL 40

Expert Comment

ID: 33662715
Open report from example
LVL 58

Accepted Solution

Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 total points
ID: 33663402
<<I have copied and tweaked code.  Could anyone give me a code example?>>
  Sure, I just wasn't quite sure where to start.  First thing we need to get right though is the datasource for the report.  You are going to want one record per child/ancestor pair.  Do that with a query ( I think your already there unless what you posted above was done with a subreport).
  As far as the logic, there are a few ways to do this and I'm going to show you the one that uses the least amount of code possible.

0. Add a string variable, strChildrensNames to the reports declaration section.
1. Add a report group on the ancestorID and indicate that you want a header and a footer.
2. Set the ancestor group header's visible property to false
3. Add the following code to the OnFormat event of the header:

  strChildrensNames = ""
4. Set the detail's section visible property to false
5. Add two controls for the childs name (first and last) to the detail section.  These will be the only two controls in that section.  Call them txtChildsFirstName and txtChildsLastName (if you already have controls there, select them and move then down to the report footer).
6. Add the following code to the Detail section's OnFormat event:
If FormatCount = 1 Then
  strChildrensNames = strChildrensNames & ", " & Me.txtChildsLastName & ", " & Me.txtChildsFirstName
End If
7. Make sure the group footers visible property is True
8. Place all the controls you need here for the ancestor info.
9. Add one un-bound control to hold the childern's names were collecting in the OnFormat event in the detail section.  Call it txtChildrensNames
10. Add the following code to the OnFormat event of the group footer:

  Me.txtChildrensNames = Mid$(strChildrensNames, 3)

All right...that's it.  Here's what is happening:

Were getting one record per child/ancestor pair and we've set the grouping on the ancestor, with the header for that group and the detail section set so they won't print.  What we'll get then is one line on the report (the group footer) for each ancestor.

But even though the group header and detail section are not visible, any code we have there still get's done. The report engine will do group header when the ancestor changes and the detail section for each record in the recordsource.  

In the instructions above, the code clears the variable were using to hold the names, and the detail section code collects each childs name and saves it in strChildrensNames.
When the report engine hits the last child record for an ancestor, it will do the report footer.  It's here that you print the ancestor info required and where we take the children's names we've collected and place them in a control in the group footer.
 The Mid$() function is stripping out the comma and space that appears at the start of the names.
  There are other methods that you can do to do this (utilizing MoveLayout, NextRecord, and PrintSection properties), but that is more complex and overkill for what you're trying to do here.
 Give it a swing and if you get stuck, let me know and I can whip up a sample.

LVL 48

Expert Comment

by:Dale Fye
ID: 33663639
You might also be able to address this with a subform for the children.  You can define your subform for multiple columns that run horizontally, then wrap to the next line.

Author Comment

ID: 33665417
Could you take a look ath this?  For some reason my string variable isn't picking up the names
LVL 58
ID: 33665974
<<Could you take a look ath this?  For some reason my string variable isn't picking up the names>>
  You did perfect!   And the answer is simple as to why it is not working; use Print Preview and not Report View.   In Report View, no code is executed (have no idea of what they were thinking of when they did this).
 I would make a couple of small changes however.  In your table, don't name the fields starting with the 'txt' prefix.  The whole idea of that prefix is to indicate a text control.  By naming a control that way in a form or report and not doing that for fields, it's very easy to tell in code if your dealing with a control or a field (and there are times you want to know that).  Access also doesn't have to guess what your referring to because the names are different, so it will be faster.
 There are a whole bunch of standardized prefixes that you can use.  One you might want to look at is:
 which has been around for ages.  There is nothing saying you can't use your own pre-fixes if you want.  The important thing is that your consistent in naming everything.  This makes it easier when you go back to the app after a time and want to make changes.
  Also, your names look a bit funny in the report, but that's because you have so many nulls in for the last name.  When you plug in the values, it will look fine (there are comma's in to seperate the names, as well as the first and last names, which you might want to change).
 One last thing; how I trouble shooted this was to place a STOP in the code at the start of each procedure.  This is how I discovered that the procedures were not executing.  Took me a minute to figure out what was going on (I don't use 2007).
 The other thing that lets you do is actually step through the code line by line by pressing F8.  You can also hover the mouse over a variable and see it's value.  You can continue code execution by pressing F5.
 There are other things you can do when stepping through the code, but I'll stop there.

Author Closing Comment

ID: 33666980
Thanks so much for the time you put into helping me with this and for solving my problem for me!!

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question