CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2002

    how remove item in combobox in vba??,

    removeitem doesn't work in vba, i reach the method in vba...

  2. #2
    Join Date
    Sep 2001
    Québec, Canada
    If your combobox is linked to a table (a datasource), you will not be able to remove ONE item, you'll have to set the combobox independant. The items are stored in the RowSource property like this "item1;item2;item3". The following code can be used in a more general function, it will remove the second item of a combobox, for example, the "item1;item2;item3" will become "item1;item3". There is surely a better way to do it (like with SendMessage), but for now...

        Dim x As Integer  'X - For loop indice
        Dim indiceItem As Integer 'The indice of the current loop item
        Dim indiceItemToRemove As Integer 'The indice of the item you want to remove
        Dim strOld As String 'The old string of the RowSource combobox
        Dim strNew As String 'The modified string of the RowSource combobox
        Dim strCar As String 'The current car of the loop
        'Getting the items of the combobox to modify
        strOld = Me.ComboBox1.RowSource
        'Always start at indiceItem = 1
        indiceItem = 1 
        'We'll remove the item number 2
        indiceItemToRemove = 2 
        'strNew will be the modified string
        strNew = ""
        'Add all characters to strNew from strOld, except those who are in the
        'indiceItemToRemove range (separated by ";")
        For x = 1 To Len(strOld)
            strCar = Mid(strOld, x, 1)
            If strCar = ";" Then
                If indiceItem <> indiceItemToRemove Then
                    strNew = strNew & strCar
                End If
                indiceItem = indiceItem + 1
                If indiceItem <> indiceItemToRemove Then
                    strNew = strNew & strCar
                End If
            End If
        Next x
        'Change the combobox datas
        Me.ComboBox1.RowSource = strNew
        Me.ComboBox1.Value = ""
    It is quite strange that method do not exist... if someone find it, would be nice to let use know


  3. #3
    Join Date
    Feb 2001
    Stamford CT USA
    Is this in Access? I've tried it in Excel and it works.

    -Cool Bizs

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.