How to build a dynamic matrix type report

Posted on 2006-04-05
Medium Priority
Last Modified: 2012-05-05
I just can't get my head around this and could use some help. I have a dynamic list of tech employees and will be maintained by an admin. The admins which check a Tech checkbox to make an employee show on the tech list.  We then have a list of clients, with one tech assigned to each client. The tech assignments will also be maintained by the admin to keep updated.

I need a report that will list the employees across the screen, list the Clients down the left column, with an X in the intersecting cell. At the bottom of the report, each employee will have a total number of client assignments.

Company   Employ1  Employ2  Employ3
----------- ----------- ----------- ----------
A               X
B                                              X
C                                 X
D               X
----------- ----------- ----------- ---------
Total         2                1            1

I can do this report if I hard code the employees and perform an Onformat event to see which column gets the X, and create variables to track how many X's are assigned to a given hard coded cell.  But I would like the columns to be dynamic as I know the list of techs will change down the road.

Any idea's how to approach this?
Question by:Thirt
  • 2
LVL 54

Accepted Solution

nico5038 earned 1000 total points
ID: 16385101
Making the columnheader and detaildata flexible is possible, but needs some VBA code in the OpenReport event.

To start, doing this you need to place the fields "coded" in the report.
The column headings should be called "lblCol1", "lblCol2", "lblCol3", etc.
The "detail" fields should be called "Col1", "Col2", "Col3", etc.

The report query has two rowheader columns and a Total column, therefor the first field is effectively column 4 (count starts at 0 so I used intI=3) but this could differ for you.

Make sure that the number of Columns is not bigger as the number placed. The programcode has no protection against that !

The OpenReport code:

Private Sub Report_Open(Cancel As Integer)
Dim intI As Integer

Dim rs As Recordset

Set rs = CurrentDb.OpenRecordset(Me.RecordSource)

'Place headers
For intI = 3 To rs.Fields.Count - 1
Me("lblCol" & intI - 1).Caption = rs.Fields(intI).Name
Next intI

'Place correct controlsource
For intI = 3 To rs.Fields.Count - 1
Me("Col" & intI - 1).ControlSource = rs.Fields(intI).Name
Next intI

'Place Total field
Me.ColTotal.ControlSource = "=SUM([" & rs.Fields(2).Name & "])"

End Sub

The report query has two rowheader columns and a Total column, therefor the first field is effectively column 4 (count starts at 0 so I used intI=3) but it could differ for you.

Clear ?


Author Comment

ID: 16387126
I think I follow that. I will need to follow up on this later, as I went ahead and completed the hard coded columns.

But a quick question, on the On-format event, I'm placing the X in the correct hard code column using a Case select. How do I keep a running total for the given columns when I place an X in it?

I was thinking of trying to following...
    Select Case fldemployeeindexno
        Case 378
            Me.coltj = "X"
            Me.colmb = ""
            Me.coltc = ""
            Me.coltb = ""
            Me.coljs = ""
            Me.colun = ""
            Me.txttj = 1
            Me.txtmb = 0
            Me.txttc = 0
            Me.txttb = 0
            Me.txtjs = 0
            Me.txtun = 0

But the control that performs sum([txttj]) doesn't find that control.

So how do I keep a running total for each column?
LVL 54

Expert Comment

ID: 16392383
For a sum you can use:
this will ignore the "X".


Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

850 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