how remove item in combobox in vba??,
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: how remove item in combobox in vba??,

  1. #1
    Join Date
    Aug 2002
    Location
    paris
    Posts
    136

    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
    Location
    Québec, Canada
    Posts
    1,923
    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...

    Code:
      
        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
            Else
                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

    JeffB

  3. #3
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167
    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

This is a CodeGuru survey question.


Featured


HTML5 Development Center