表格1
ID Division Dept
001 CS IT
002 CD Admin
003 AS Admin
我想在列表框中加载没有重复值的部门
尝试过的代码
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
输出
Listbox1
Admin 'Loaded for CD Division
Admin 'Loaded for AS Division
上面的代码工作正常,但它加载了 2 次管理部门。在列表框中。因为 For Loop 正在为 CD 加载部门管理员,并且再次为 AS 部门加载部门管理员。
我不想在列表框中显示重复的值。
预期产出
Listbox1
Admin 'Loaded for both CD and AS Division
如何在 VB6 中做到这一点。
需要 VB6 代码帮助。