Show multiple record in one text box access report (1 Viewer)

rubenstranger46

New member
Local time
Tomorrow, 05:58
Joined
Mar 26, 2021
Messages
5
Hii..im newbie in access..i have problem in my access report.is there anyone can help me?

ex table/query:
id_number | category
027-001 | Good
027-001 | Great

i would like to create report with this table/query, into this report:

id_number | Category
027-001 | Good, Great

is there possible?thanks for help
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:58
Joined
May 7, 2009
Messages
19,229
search for Allen Brownes ConcatRelated() function.
Code:
' Allen Browne
' USAGE:
' SELECT CompanyName,  ConcatRelated("OrderDate", "tblOrders", "CompanyID = " & [CompanyID])
' FROM tblCompany;
Public Function ConcatRelated(strField As String, _
    strTable As String, _
    Optional strWhere As String = "", _
    Optional strOrderBy As String = "", _
    Optional strSeparator = ", ") As Variant
On Error GoTo Err_Handler
    'Purpose:   Generate a concatenated string of related records.
    'Return:    String variant, or Null if no matches.
    'Arguments: strField = name of field to get results from and concatenate.
    '           strTable = name of a table or query.
    '           strWhere = WHERE clause to choose the right values.
    '           strOrderBy = ORDER BY clause, for sorting the values.
    '           strSeparator = characters to use between the concatenated values.
    'Notes:     1. Use square brackets around field/table names with spaces or odd characters.
    '           2. strField can be a Multi-valued field (A2007 and later), but strOrderBy cannot.
    '           3. Nulls are omitted, zero-length strings (ZLSs) are returned as ZLSs.
    '           4. Returning more than 255 characters to a recordset triggers this Access bug:
    '               http://allenbrowne.com/bug-16.html
    Dim rs As DAO.Recordset2         'Related records
    Dim rsMV As DAO.Recordset2       'Multi-valued field recordset
    Dim strSQL As String            'SQL statement
    Dim strOut As String            'Output string to concatenate to.
    Dim lngLen As Long              'Length of string.
    Dim bIsMultiValue As Boolean    'Flag if strField is a multi-valued field.
   
    'Initialize to Null
    ConcatRelated = Null
    'Build SQL string, and get the records.
    strSQL = "SELECT [" & strField & "] FROM " & strTable
    If strWhere <> vbNullString Then
        strSQL = strSQL & " WHERE " & strWhere
    End If
    If strOrderBy <> vbNullString Then
        strSQL = strSQL & " ORDER BY " & strOrderBy
    End If
    Set rs = DBEngine(0)(0).OpenRecordset(strSQL, dbOpenDynaset)
    'Determine if the requested field is multi-valued (Type is above 100.)
    bIsMultiValue = (rs(0).Type > 100)
   
    'Loop through the matching records
    Do While Not rs.EOF
        If bIsMultiValue Then
            'For multi-valued field, loop through the values
            Set rsMV = rs(0).value
            Do While Not rsMV.EOF
                If Not IsNull(rsMV(0)) Then
                    strOut = strOut & rsMV(0) & strSeparator
                End If
                rsMV.MoveNext
            Loop
            Set rsMV = Nothing
        ElseIf Not IsNull(rs(0)) Then
            strOut = strOut & rs(0) & strSeparator
        End If
        rs.MoveNext
    Loop
    rs.Close
   
    'Return the string without the trailing separator.
    lngLen = Len(strOut) - Len(strSeparator)
    If lngLen > 0 Then
        ConcatRelated = left(strOut, lngLen)
    End If

Exit_Handler:
    'Clean up
    Set rsMV = Nothing
    Set rs = Nothing
    Exit Function

Err_Handler:
   
   
    MsgBox "Error " & Err.Number & ": " & Err.description, vbExclamation, "ConcatRelated()"
    Resume Exit_Handler
End Function

your query:

select id_number, ConcatRelated("category","yourTable","id_number = '" & [id_number] & "'") as category
from yourTable group by id_number, ConcatRelated("category","yourTable","id_number = '" & [id_number] & "'")

now, create a report based on the query.
or on existing report, put the sql as the recordsource of your report.
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 15:58
Joined
Oct 29, 2018
Messages
21,454
Not sure if if this helps any better, but it's another option.

 

Users who are viewing this thread

Top Bottom