Home >Database >Mysql Tutorial >How Can I Concatenate Lists in MS Access Without a `group_concat` Function?

How Can I Concatenate Lists in MS Access Without a `group_concat` Function?

Barbara Streisand
Barbara StreisandOriginal
2025-01-04 17:35:43486browse

How Can I Concatenate Lists in MS Access Without a `group_concat` Function?

Concatenating Lists in MS Access

MS Access doesn't natively offer a group_concat function like in other databases. However, you can employ various techniques to achieve similar functionality.

One option is to use VBA code. If you only need it for a specific purpose, a quick and easy approach is to simply concatenate the list items using the & operator. The code snippet below demonstrates this method:

Dim strOutput As String

For Each record In rs
    If Len(strOutput) = 0 Then
        strOutput = record.Item("Value")
    Else
        strOutput = strOutput & ", " & record.Item("Value")
    End If
Next

If you need a more generic solution, you can utilize the trick suggested by Access expert Trevor Best. Instead of adding the delimiter at the end of each value, append it to the beginning. Then, use the Mid() function to remove it:

strOutput = "delimiter" & NewValue

Finally, strip the leading delimiter when exiting the loop:

strOutput = Mid(strOutput, 3)

This technique simplifies concatenation in various scenarios within VBA code.

The above is the detailed content of How Can I Concatenate Lists in MS Access Without a `group_concat` Function?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn