Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8227133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:01:06+00:00 2026-06-07T16:01:06+00:00

Table1 ID Division Dept 001 CS IT 002 CD Admin 003 AS Admin I

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:01:08+00:00Added an answer on June 7, 2026 at 4:01 pm

    Write a function to check if it’s already in the list…

    Public Function FindInList(theList as ListBox, theString as String)
        Dim i as Integer
        theString = LCase(Trim(theString))
    
        For i = 0 to theList.ListCount - 1
            If LCase(Trim(theList.List(i))) = theString then
                FindInList = i
                Exit Function
            End If
        Next i
    
        FindInList = -1
    End Function
    

    And then when you want to add things to the list, just do…

    If FindInList(List1, StringToAdd) = -1 Then List1.AddItem(StringToAdd)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Table1 ID Loc ----------- 001 null 002 null 003 PYD 004 null .... Table2
Table1 ID | WorkTime ----------------- 001 | 10:50:00 001 | 00:00:00 002 | ....
Table1 ID product 001 LG 001 Sony 001 LG 001 LG 001 Sony 001
Table1 Date id salary 01/2012 001 1500 01/2011 001 750 01/2010 001 500 from
I have 4 different values, i want to check 4 values with 4 different
At the moment I have this code: $divisions = explode(,, $mychecklist->dept); foreach($divisions as $division)
I want to make a select query with an and condition. dept, divi, comp
I have the following database design: Employee Table: Username, Name, DivisionCode Division Table: SapCode,
In my data model I have a fairly common division between my objects/tables/data: Transactional
table1 is the parent table with a column ID and table2 has a column

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.