S
samirk
I have a table with data similar to:
Num String
1 String 1A
1 String 1B
1 String 1C
2 String 2A
2 String 2B
3 String 3
....
and would like a query/table with the result:
1 String 1A; String 1B; String 1C
2 String 2A; String 2B
3 String 3
----------
After reading the forums, I was able to find this function below and now I
call it in a query that has a Group By on the Num field. Unfortunately, some
of these strings 1A, 1B 1C etc. can be long and the result is getting
truncated to 255 characters. I read a KB article and have tried to change
the query to become an Append Table query with a memo field in the table to
hold the result, but no luck. Is there a way I can accomplish what I need
(and ideally, make it run faster too!).
---------
Public Function ConCatField(pstrTable As String, pstrField As String,
Optional pstrCriteria As String = "", Optional pstrOrderBy As String,
Optional pstrDelimiter As String = "; ") As String
Dim rs As New ADODB.Recordset
rs.Open "Select [" & pstrField & "] FROM [" & pstrTable & "]" &
IIf(Len(pstrCriteria) > 0, " WHERE " & pstrCriteria, "") &
IIf(Len(pstrOrderBy) > 0, " ORDER BY " & pstrOrderBy, ""),
CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
If Not rs.EOF Then
ConCatField = rs.GetString(adClipString, , "", pstrDelimiter)
ConCatField = Left(ConCatField, Len(ConCatField) - Len(pstrDelimiter))
End If
rs.Close
Set rs = Nothing
End Function
--------
Num String
1 String 1A
1 String 1B
1 String 1C
2 String 2A
2 String 2B
3 String 3
....
and would like a query/table with the result:
1 String 1A; String 1B; String 1C
2 String 2A; String 2B
3 String 3
----------
After reading the forums, I was able to find this function below and now I
call it in a query that has a Group By on the Num field. Unfortunately, some
of these strings 1A, 1B 1C etc. can be long and the result is getting
truncated to 255 characters. I read a KB article and have tried to change
the query to become an Append Table query with a memo field in the table to
hold the result, but no luck. Is there a way I can accomplish what I need
(and ideally, make it run faster too!).
---------
Public Function ConCatField(pstrTable As String, pstrField As String,
Optional pstrCriteria As String = "", Optional pstrOrderBy As String,
Optional pstrDelimiter As String = "; ") As String
Dim rs As New ADODB.Recordset
rs.Open "Select [" & pstrField & "] FROM [" & pstrTable & "]" &
IIf(Len(pstrCriteria) > 0, " WHERE " & pstrCriteria, "") &
IIf(Len(pstrOrderBy) > 0, " ORDER BY " & pstrOrderBy, ""),
CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
If Not rs.EOF Then
ConCatField = rs.GetString(adClipString, , "", pstrDelimiter)
ConCatField = Left(ConCatField, Len(ConCatField) - Len(pstrDelimiter))
End If
rs.Close
Set rs = Nothing
End Function
--------