How to Display All Unique Values in a Textbox
Many users prefer to display all unique field values in a text box. This requirement can be achieved using the Code Module and LookupSet function. Follow the steps below to show all unique dataset field values in the text box.
-
To remove duplicate values and return the unique values as a comma-separated string, include the provided VB code module. Embed the code module function into the Code Section of your report. This module introduces a function named
RemoveDuplicates
, which eliminates duplicate values from an array and generates a comma-separated string of unique values.
Function RemoveDuplicates(items As Object()) As String Dim uniqueValues As New System.Collections.Generic.Dictionary(Of String, Boolean) For Each item As Object In items Dim value As String = item.ToString() If Not uniqueValues.ContainsKey(value) Then uniqueValues.Add(value, True) End If Next Return String.Join(", ", uniqueValues.Keys) End Function
-
Right-click on the desired text box, then select Expression.
-
Insert the following expression into the text box to retrieve unique values as a comma-separated list:
=Code.RemoveDuplicates(LookupSet(1, 1, Fields!Name.Value, "DataSet1"))
Replace DataSet1 with your dataset and Name with the appropriate field name.
- Save the changes and preview the report to visualize all unique values within the text box.
The above-designed report can be downloaded here.