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

x
?
Solved

Crosstab query multi-value string output

Posted on 2013-12-24
6
Medium Priority
?
119 Views
Last Modified: 2016-05-14
I have an MS Access table that defines security setup.  Access to a form is granted by task and then tasks to roles.  The same form may be granted access as part of different tasks.  Here is some sample data:

ROLE                TASK                          FORM            ACCESS LEVEL
AP Admin        Vendor Setup           AP01              All Access
AP Admin        Company Setup       AP01              All Access
AP Admin        Payables Inquiry      AP01              Inquiry Only
AP Clerk           Vendor Setup           AP01              All Access
AP Clerk           Enter Invoice            AP01              All Access

I have two separate crosstab queries where there are rows for each form name and columns for each role to display the task name (in one) and access level (in another).  But for those instances where there are two or more intersections of form and role, I'd like the crosstab query to display text which concatenates the multiple values of task name.

Can this be done in MS Access?  And if so, how?

Thanks so much!
0
Comment
Question by:scdallas
[X]
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
6 Comments
 
LVL 48

Accepted Solution

by:
Dale Fye earned 2000 total points
ID: 39738094
Best method is to create a function, something like (untested air code):
Public Function fnConcat(FieldName as string, TableQueryName as string, _
                                            Optional Criteria as String = "")

    Dim strSQL as String
    Dim rs as DAO.Recordset

    On Error Goto ProcError

    strSQL = "SELECT [" & FieldName & "] FROM [" & TableQueryName & "] "
    if Criteria <> "" then
        strSQL = strSQL & "WHERE " & Criteria
    endif

    set rs = Currentdb.openrecordset(strsql, , dbfailonerror)
    While not rs.EOF
        fnConcat = fnConcat & ", " & rs(FieldName)
        rs.movenext
    Wend
    
    'strip off leading comma and space
    if Len(fnConcat) > 0 then fnConcat = Mid(fnConcat, 3)

ProcExit:
    On Error Resume Next
    rs.close
    set rs = nothing
    Exit Function

ProcError:
    msgbox err.number & vbcrlf & err.description & vbcrlf & strSQL, vbOkOnly
    debug.print err.number, err.description
    debug.print strSQL
    Resume ProcExit

End Function

Open in new window

Then call that function from your query:

SELECT [Form], [Role], fnConcat("Task", "yourTableName", "[Form] = '" & [Form] & "' AND [Role] = '" & [Role] & "'") as Tasks
FROM yourTableName
GROUP BY [Form], [Role]

Then convert this to a crosstab
0
 
LVL 31

Expert Comment

by:hnasr
ID: 39738632
Show sample output of cross tab queries, and required output. Why there are two queries?
0
 

Author Comment

by:scdallas
ID: 39746814
I have two cross tab queries to show by form and role the first task and access level values.  For the above data, the output for these looks like:

FORM           APADMIN TASK           APCLERK TASK
AP01             Vendor Setup              Vendor Setup
AP02
AP03

FORM           APADMIN ACCESS        APCLERK ACCESS
AP01             All Acc ess                     All Access
AP02
AP03

And then I have a third query to consolidate those so that there are two columns per Role.

Realize that there are thousands of forms, hundreds of tasks, and about 50 roles.  Also, I'm using the basic Access query design rather than writing total code.  What I'd like, ultimately, is something that looks like:

FORM   APADMIN TASKS                                                         APADMIN ACCESS
AP01     Vendor Setup, Company Setup, Payables Inquiry  All Access, All Access, Inquiry Only
AP02
AP03

        with the same two columns for each role value.

Does this make more sense?
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 39746887
Have you tried the fnConcat code I provided?  It will get you to:

Form              Role                            Tasks
AP01            APADMIN Tasks        Vendor Setup, Company Setup, Payables Inquiry
AP01            APADMIN Access      All Access, All Access, InquiryOnly

Then you would simply change that query to a crosstab, set the Form to RowHeader, Role to ColumnHeader and Tasks to Value (Expression)
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 41594498
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

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

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

610 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