Results 1 to 5 of 5

Thread: Remove Duplicate Item From Combo Box

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Location
    Sri Lanka
    Posts
    5

    Remove Duplicate Item From Combo Box

    I want to Remove Duplicate Item From the Combo Box.

    How to Remove Duplicate Item?
    Vijay

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Use the RemoveItem method

    Combo1.RemoveItem <Index number of item to be removed>

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Remove Duplicate Item From Combo Box

    Originally posted by vijayarajah
    I want to Remove Duplicate Item From the Combo Box.

    How to Remove Duplicate Item?
    Do you want to stop from being added in the fisrt place or do you just want to remove all duplicates?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Here is something to get you started.
    VB Code:
    1. Option Explicit
    2.  
    3. Public Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
    4. ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
    5.  
    6. Private Const CB_FINDSTRINGEXACT = &H158
    7. Private Const CB_FINDSTRING = &H14C
    8.  
    9. Public Function SearchCBO(ByRef cboCtl As ComboBox, ByVal sSearchCriteria As String, Optional ByVal bLIKE As Boolean) As Long
    10. '<RR 08/08/2003 - VB/OUTLOOK GURU>
    11.     On Error GoTo No_Bugs
    12.    
    13.     If bLIKE = False Then 'EXACT MATCH
    14.         SearchCBO = SendMessageStr(cboCtl.hwnd, CB_FINDSTRINGEXACT, 0&, ByVal sSearchCriteria)
    15.     Else 'LIKE MATCH
    16.         SearchCBO = SendMessageStr(cboCtl.hwnd, CB_FINDSTRING, 0&, ByVal sSearchCriteria)
    17.     End If
    18.     Exit Function
    19.    
    20. No_Bugs:
    21.     MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbInformation
    22. End Function
    23.  
    24. Private Sub Command1_Click()
    25.    
    26.     If SearchCBO(Combo1, Combo1.Text, False) > -1 Then
    27.         'Exists already
    28.     Else
    29.         'Not found in combo
    30.     End If
    31.    
    32. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    Since I saw that you had an earlier thread about connecting VB app to remote ACCESS DB...

    That makes me think I should ask you where the duplicates are coming from? Are you executing a QUERY that is giving you duplicates?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width