Transpose Vertical text values to Horizontal

HickoryII

New member
Local time
Today, 14:42
Joined
Aug 1, 2008
Messages
7
I have a Volunteer Database that has teams. There is only one team leader but some of the teams have two or three assistants. Currently I have a query that lists all the assistants for each team vertically.
I've attached a picture of the query I'm using.
What I want to do is list the Assistants horizontally under headings like Assistant 1; Assistant 2; and Assistant 3 for each team on one line.
Can someone tell me how to do this? Your help would be much appreciated!
Hickory II :o
 

Attachments

  • qryTeamAssistants.jpg
    qryTeamAssistants.jpg
    90.2 KB · Views: 185
You could use a crosstab query - providing you have a field which says 'assistant1' or 'assistant2' etc, otherwise Access does no know which column to put an assistant in.

If such a field exists, this is the column heading, the value heading would be the assistant name and set to 'first' whilst all the other columns would be row headings
 
Right now they are all listed as simply Assistant in the "Description" column. I'm kind of new to this so if you could explain a little more fully exactly how I go about setting this up I'd be very grateful. Thanks:o
 
Yeah, so basically you have to have a column to your table... maybe call it: [Job level].

Once you add that caolumn to your table, you will then have to go through and tag each person with a designation (e.g. "Team Leader" or "Assistant 1", "Assistant 2" etc... etc..)

Once you have everyone designated, you can then make a crosstab query using the Team designation as your record value, the [Job Level] as your column value... and the names of the people as the crosstab values.

GL
 
Here is something I copied a few years ago but never actually used so I can't say how well it works. It sounds like just what you want.
Code:
ConcatenateFieldValues

This function is based a function named "Concatenate" that was originally written by Duane Hookom (ACCESS MVP); he has a sample database that contains the function. It is used to create a concatenated string from a single field's values from all the records desired to be included in the concatenated string. The records to be included, plus the field to be used for creating the concatenated string, are specified by an SQL statement that is passed to the function. The SQL statement passed to the function must return only one field in order for this function to work correctly. The values in the concatenated string are separated by a character string that is provided to the function as a delimiter string (if no delimiter is provided, the function uses a comma followed by a space).

Public Function ConcatenateFieldValues(pstrSQL As String, _
      Optional pstrDelim As String = ", ") As String

' Created by Duane Hookom, 2003
' this code may be included in any application/mdb providing
'      this statement is left intact
' example
'      tblFamily with FamID as numeric primary key
'      tblFamMem with FamID, FirstName, DOB,...
' return a comma separated list of FirstNames for a FamID
'                  John, Mary, Susan
'      in a Query
'            SELECT FamID,
'            ConcatenateFieldValues("SELECT FirstName 
'            FROM tblFamMem WHERE FamID =" & [FamID]) AS FirstNames
'            FROM tblFamily;
'---------------------
' Modified by Ken Snell 29 October 2005

' *** THIS FUNCTION BUILDS A CONCATENATED STRING THAT CONTAINS
' *** THE VALUES OF ONE FIELD FOR EACH RECORD IN A TABLE OR
' *** QUERY, WITH EACH VALUE SEPARATED BY A SPECIFIED DELIMITER.

Dim strConcat As String

'======For ADO comment next 2 lines and =======
'====== uncomment out ADO lines below =======
Dim db As DAO.Database
Dim rs As DAO.Recordset

On Error Resume Next

strConcat = ""

'======For ADO comment out next 2 DAO lines and =======
'====== uncomment ADO lines below =======
Set db = CurrentDb
Set rs = db.OpenRecordset(pstrSQL)

'======For ADO uncomment next two lines and =====
'====== comment out DAO lines above and below ======
' Dim rs As New ADODB.Recordset
' rs.Open pstrSQL, CurrentProject.Connection, _
'       adOpenKeyset, adLockOptimistic

With rs
      If Not .EOF Then
            .MoveFirst
            Do While Not .EOF
                  strConcat = strConcat & .Fields(0) & pstrDelim
                  .MoveNext
            Loop
      End If
      .Close
End With

Set rs = Nothing

'====== Comment next 2 lines for ADO ========
db.Close
Set db = Nothing

If Len(strConcat) > 0 Then strConcat = _
      Left(strConcat, Len(strConcat) - Len(pstrDelim))

ConcatenateFieldValues = strConcat

Exit Function
End Function
 
Thanks for all the input from everyone. I'm sure I'll be able to achieve the desired results with the references so helpfully provided; especially the one offered by Galaxiom. This is a wonderful forum for solving Access problems. :)
 

Users who are viewing this thread

Back
Top Bottom