compare combobox and listbox

pm4698

Registered User.
Local time
Today, 11:11
Joined
Jan 23, 2010
Messages
72
Hi there! This question of mine came from another thread of mine, but i thought i should post it as a new thread.

I have a combo box and a listbox.
All i want is when i select a value(text) from the combobox to check if there is a same value(same text) at the listbox and if there is, then this value will be removed from the listbox.
I tried at after update combobox this:
Dim lnI As Integer

For listbox_name= 1 To listbox_name.ListCount
If listbox_name.List(lnI) = combobox_name.Value Then
listbox_name.List(lnI) = ""
End If

Next lnI

but its not working

Any ideas?

Thank you a lot!
 
Try This

Code:
For nIndex = 0 To Me.ListBox.Count -1
   If Me.Listbox([COLOR="Red"]nIndex[/COLOR],[COLOR="Blue"]1[/COLOR]) = Me.ComboBox Then
      Me.ListBox.RemoveItem(nIndex)
      Exit For
   End If
Next

Where nIndex is the index list number and 1 is the column number that the matching data appears in.
 
I get a compile error:
method or data member not found.
and the .Count is highlighted.
 
Typo try .ListCount

All code is air code and untested and field/controls names are for brevity only.
 
I changed it and then i had a compile error at
me.listbox(nIndex,1).

Its something it does not identify this. I also tried
me.listbox.itemdata (nIndex,1) or
me.listbox.recordset(nIndex,1) but i get an error for removeitem:
runtime error '6014':
The rowsource type property must be declared at "record list" so i can use this method.

Any ideas?
 
Try;

Code:
For i = 0 To Me.ListBox.ListCount - 1
   If Me.ListBox.Column(0, i) = Me.ComboBox.Value Then
   Call RemoveListItem(ListBox, i)
      Exit For
   End If
Next i
 

Function RemoveListItem(ctrlListBox As ListBox, ByVal varItem As Variant) As Boolean
    ' Trap for errors.
    On Error GoTo ERROR_HANDLER
    ' Remove the list box item and set the return value
    ' to True, indicating success.
    ctrlListBox.RemoveItem Index:=varItem
    RemoveListItem = True
    ' Reset the error trap and exit the function.
    On Error GoTo 0
    Exit Function
' Return False if an error occurs.
ERROR_HANDLER:
    RemoveListItem = False
End Function
 
At your code i changed only at the FOR routine, the listbox and the combobox with my listbox name and combobox name. I checked this out,
but nothing happens.
I can select a choice from the combobox without getting any errors but despite i am updating the form. the selected choice does not get removed from the list.

Any suggestions?
 

Users who are viewing this thread

Back
Top Bottom