How to build a dynamic matrix type report

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?
Who is Participating?
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 ?

ThirtAuthor Commented:
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?
For a sum you can use:
this will ignore the "X".

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.