0

I have a challenging problem I'm attempting to solve and could use your expertise in this matter.

I am attempting to replicate some reports in Access 2013 using queries that I otherwise get from the front-end application to a FootPrints Service Core 11.6 Database. I've completed queries and calculations to replicate most fields from the front end reports, except for the assignee information.

(Note: Assignee is the individual or [generally] teams that a ticket is assigned to for work, can be multiple [teams and individuals])

These assignees are listed out separately within an assignees table of FootPrints Database (See attached images). When the front end application generates reports it somehow groups together the individual and team assignee information in a particular way I'm unable to emulate (See Image). This is where I need your help!

I need to combine all the assignees (individual and team assignees) within a single field, grouped by the ticket number (mrID) they associate with.

So, where there is the following in the database

MrID | Assignee | Team

12345 | Bob Smith | Help Desk Tier 1

12345 | Jane Smith | Help Desk Tier 1

12345 | (Null) | Telecom

23456 | (Null) | Help Desk Tier 2

34567 | Chuck Norris | (Null)

45678 | (Null) | Help Desk Tier 1

45678 | (Null) | Help Desk Tier 2

45678 | (Null) | Networking

45678 | (Null) | Access Control

It should appear as 1 field, like this:

MrID | Assignees

12345 | Help Desk Tier 1: Bob Smith, Jane Smith. Telecom:

23456 | Help Desk Tier 2:

34567 | Chuck Norris

45678 | Help Desk Tier 1: . Help Desk Tier 2: . Networking: . Access Control:

As you can see in the above example, each team assignee is followed by a :, multiple team members (individuals) are seperated by ,'s, and multiple teams are separated by .'s

Following this convention Is there a way to mimic this process through the use of a query (or VBA if necessary) in Access?

Sincerely,

Kris

A standard report, showing how the assignee field is grouped and concatenated

The Assignees Table of the Database, the way the assignee info is natively stored.  Note: Names blacked out for privacy reasons

The Assignees Table of the Database, the way the assignee info is natively stored.  Note: Names blacked out for privacy reasons

2
  • 2
    Questions like this are a bit too broad for Stack Overflow. This requires a VBA solution, you can search for the source code of ConcatRelated and start with that, or write it from scratch, but we're not really in the hinting business. Commented Jun 11, 2019 at 14:29
  • Sincerest apologies, Erik! I am unable to provide a copy of the dataset due to it including PII. I tried to capture the associated fields within the screenshots provided, I know it was very little to work off of. I thought there may be a query only solution, but figured there was a good chance it would require VBA to complete. Commented Jun 11, 2019 at 15:10

1 Answer 1

1

You have not provided enough data to make more tests. Yes, you included screenshots, but data to copy and paste just 3 records, so I worked with that

I replied your table like this (name of my table is Table1): enter image description here

Then, I have a Query like this:

enter image description here

The SQL code for this query is:

SELECT DISTINCT Table1.MrID, FINAL_ASSIGNEES([mrid]) AS ASSIGNEES FROM Table1;

As you can see, this SQL code invokes an UDF coded in VBA named FINAL_ASSIGNEES. The code of this UDF is:

Public Function FINAL_ASSIGNEES(ByVal vThisMrID As Long) As String
Dim RST As Recordset
Dim SqlStr As String

SqlStr = "SELECT DISTINCT Table1.MrID, CONCATENATE_ASSIGNEE([MrID],[Team]) AS ASSIGNEES FROM Table1 " & _
    "WHERE Table1.MrID=" & vThisMrID & ";"

Set RST = Application.CurrentDb.OpenRecordset(SqlStr, 2, 4)

With RST
    If .EOF <> True And .BOF <> True Then
        .MoveLast
        .MoveFirst
        Do Until .EOF = True
            FINAL_ASSIGNEES = FINAL_ASSIGNEES & .Fields(1).Value & ". "
            .MoveNext
        Loop
            FINAL_ASSIGNEES = Left(FINAL_ASSIGNEES, Len(FINAL_ASSIGNEES) - 2) 'minus 2 to get rid of extra ". "
    End If

    Set RST = Nothing
End With


End Function

And yes, this VBA code calls a second UDF named CONCATENATE_ASSIGNEE. The code of this second UDF is:

Public Function CONCATENATE_ASSIGNEE(ByVal vMrID As Long, ByVal vTeam As String) As String
Dim MyRST As Recordset
Dim MySQL As String

MySQL = "SELECT Table1.Assignee FROM Table1 " & _
    "WHERE (((Table1.MrID)=" & vMrID & ") AND ((Table1.Team)='" & vTeam & "'));"

Set MyRST = Application.CurrentDb.OpenRecordset(MySQL, 2, 4)
DoEvents

With MyRST
    If .EOF <> True And .BOF <> True Then
        .MoveLast
        .MoveFirst

        Do Until .EOF = True

            If IsNull(.Fields(0)) = True Then
                CONCATENATE_ASSIGNEE = CONCATENATE_ASSIGNEE & "Unassigned" & ", "
            Else
                CONCATENATE_ASSIGNEE = CONCATENATE_ASSIGNEE & .Fields(0).Value & ", "
            End If

            .MoveNext
            DoEvents
        Loop

        CONCATENATE_ASSIGNEE = vTeam & ": " & Left(CONCATENATE_ASSIGNEE, Len(CONCATENATE_ASSIGNEE) - 2) 'minus 2 to get rid of the extra ", "
    End If
    Set MyRST = Nothing
End With



End Function

But this gets kind of what you are after. If you are working with big recordsets, probably it will take some time to make calculations. But at least you can adapt this to your needs.

Sign up to request clarification or add additional context in comments.

8 Comments

Hi Foxfire! I haven't had the chance to test this out yet but I wanted to take a moment to thank you for the tremendous work you put into this response!! My sincerest apologies for being unable to provide more substantial data to work with, I can only provide screenshots of the dataset since it contains PII. There used to be a great data model available for the database I'm pulling from, here: (Unavailable now for some reason) [link] (support.numarasoftware.com/support/docs/12/116/1/…)
Forgot to respond to your question, about the size of the dataset. Currently, the dataset sits at 553,532 assignment records, covering dates from 1/1/2017 - Now(). Your code looks brilliant, and I can't wait to test it out. I will let you know the results once I do! :)
Hey, @FoxfireAndBurnsAndBurns, I've pretty much finished adjusting the code to accommodate for my exact table/field names, however, I am running into an error in the CONCATENATE_ASSIGNEE UDF. I'm getting a Run-Time error 13: Type Mismatch on the line Set MyRST = Application.CurrentDb.OpenRecordset(MySQL, 2, 4)
Read in another post regarding mismatches on these lines of code may indicate an issue with references. I tried enabled Microsoft DAO 3.6 Object Library in references of the tools menu, but it wasn't able to be loaded (Error in Loading DLL message). I don't know for sure if this is the root cause of the Mismatch error though
I was able to get it to run by changing the line Dim MyRST As Recordset to Dim MyRST As DAO.Recordset in both scripts, but even when running through a months data it doesn't complete (Takes so long). Maybe it's the load, or perhaps it's still a script issue.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.