How to build a dynamic matrix type report

Posted on 2006-04-05
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
    LVL 54

    Accepted Solution

    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 ?

    LVL 4

    Author Comment

    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

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


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
    Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now