Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to remove items from list box.

Status
Not open for further replies.

EarS

Programmer
Jun 5, 2002
26
US
What is the best way to remove selected items from a list box in VBA??? I think from what I can gather that you cannot use the listbox.RemoveItem in VBA. Or is this a problem with my access setup???
Any help is greatly appreciated!

Thanks in Advance,

Matt

When asked what he thought about when he struck out, Babe Ruth replied : "I think about hitting homeruns."
 
If you're using a "Value List" RowSourceType then set the listbox's Row Source = "".

MyListBox.RowSource = ""

I believe this only clears the list at runtime. The items originally entered in the list box property sheet reappear when you reload the form.

 

Assuming you permanently want to delete the record from the underlying table, you have two ways to do this. The first, and easiest is if the selected choice is unique. If it is not unique, you will need to carry the primary key of the underlying table in your combo box as a hidden column.
Include it as column(0) and set the size of that column to 0 inches so it will not be seen.

The subroutine below uses column(0) to delete the record and I have assumed it is text.

Public Sub subRemEntry(strKeyValue As String)

Dim strSQL As String

strSQL = "delete * from dbo_tblstate where state = '" & strKeyValue & "'"
DoCmd.RunSQL strSQL

Forms!my_form.mycombo.Requery

End Sub

To call the subroutine

subRemEntry(my_combo.column (0))
Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top