Table1
ID Division Dept
001 CS IT
002 CD Admin
003 AS Admin
I want to load the dept in the list box with out duplicate values
Tried Code
Dim rdoRs As New ADODB.Recordset
Dim record As Variant
Dim Div As Variant
Dim usr, MySQL As String
usr = "CD,AS,"
record = Split(usr, ",")
For Each Div In record
MySQL = "Select Distinct dept from table1 Where division = '" & div & "'"
rdoRs.Open MySQL, conn1
If rdoRs.RecordCount > 0 Then
Do While Not rdoRs.EOF
listbox1.AddItem rdoRs!dept
rdoRs.MoveNext
Loop
End If
rdoRs.Close
Next
Output
Listbox1
Admin 'Loaded for CD Division
Admin 'Loaded for AS Division
The above code is working fine but it is loading 2 times admin dept. in the list box. Because For Loop is loading the dept admin for CD, and again it is loading the dept admin for AS division.
I dont want to show duplicate values in the list box.
Expected Output
Listbox1
Admin 'Loaded for both CD and AS Division
How to do this in VB6.
Need VB6 Code Help.
Write a function to check if it’s already in the list…
And then when you want to add things to the list, just do…