compare values between combobox and listbox

P

pm4698

Hi there!
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 lnI = 0 To listbox_name.ListCount - 1
If listbox_name.ListIndex(lnI) = combobox_name.Value Then
listbox_name.RemoveItem (lnI)
End If

Next lnI

but its not working

Any ideas?

Thank you a lot!
 
S

Stuart McCall

pm4698 said:
Hi there!
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 lnI = 0 To listbox_name.ListCount - 1
If listbox_name.ListIndex(lnI) = combobox_name.Value Then
listbox_name.RemoveItem (lnI)
End If

Next lnI

but its not working

Any ideas?

Thank you a lot!

The RemoveItem method only works on a listbox with a 'Value List' Rowsource.
Is that the case here?
 
S

Stuart McCall

pm4698 said:
As rowsource i have a query which selects values from a table field

Stuart said:
Hi there!
I have a combo box and a listbox.
[quoted text clipped - 17 lines]
Thank you a lot!

The RemoveItem method only works on a listbox with a 'Value List'
Rowsource.
Is that the case here?

In that case you can't use RemoveItem because it simply removes an item from
the listbox's internal list, not the table, which means the listbox's data
is compromised (out of synch with the table).

You need to run a delete query then ReQuery the listbox to update it. Post
back if you need help with this.
 
M

Marshall Barton

pm4698 said:
As rowsource i have a query which selects values from a table field

If you want to leave the list box's table intact, try adding
a criteria to the query that filters the combo box value out
of the list box's RowSource:
[the field] <> Forms![the form].[the combo box]
 
P

pm4698 via AccessMonster.com

I do not want to delete the listbox value from the table. I just want to
remove it from the listbox - make it invisible. As for adding criteria, i
must do this, this way. I know the criteria - way, but i need to do this,
this way

Marshall said:
As rowsource i have a query which selects values from a table field

If you want to leave the list box's table intact, try adding
a criteria to the query that filters the combo box value out
of the list box's RowSource:
[the field] <> Forms![the form].[the combo box]
 
M

Marshall Barton

pm4698 said:
I do not want to delete the listbox value from the table. I just want to
remove it from the listbox - make it invisible. As for adding criteria, i
must do this, this way. I know the criteria - way, but i need to do this,
this way

Marshall said:
As rowsource i have a query which selects values from a table field

If you want to leave the list box's table intact, try adding
a criteria to the query that filters the combo box value out
of the list box's RowSource:
[the field] <> Forms![the form].[the combo box]

There is no way to "make it invisible". If you don't want
to see it, it should be filtered out of the list. You can
either add the criteria to the row source query or construct
the equivalent SQL statement and set the row source to the
SQL statement.

I don't see why you want to avoid that, but maybe you can
apply the filter to the list box's recordset, open another
recordset based on the list box's recordset and (re)set the
list box's recordset to the filtered recordset. I have
never tried to do anything that strange, but it might be
feasible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top