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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete item from populated listbox from database 1

Status
Not open for further replies.

obulldog27

Programmer
Apr 26, 2004
169
US
I am tring to delete a list item from a list box that is populated from a database table. When I use the following function only the first items on the list gets deleted rather then the item I have selected or highlighted.

Private delete_listitems()
compnamebox.Refresh
compnamebox.Recordset.MoveFirst
Do Until compnamebox.Recordset.EOF
If compnamebox.Recordset!ComponentName = Text1.Text Then
compnamebox.Recordset.Delete
compnamebox.Refresh
Exit Do
else if compnamebox.Recordset.EOF or
compnamebox.Recordset.BOF Then
Exit Sub
Else
compnamebox.Recordset.MoveNext
End If
Loop
End If
componentlist.Clear
Call populatecomponentcombobox
End Sub
 
you don't want to use the text value with the list box.. Rather use the "selected" property and the index property
 
Ok I have changed to selected property but I get an error: argument not optional.

--------------------------------------------------------
Private delete_listitems()
compnamebox.Refresh
compnamebox.Recordset.MoveFirst
Do Until compnamebox.Recordset.EOF
If compnamebox.Recordset!ComponentName =
componentlist.selected Then
compnamebox.Recordset.Delete
compnamebox.Refresh
Exit Do
else if compnamebox.Recordset.EOF or
compnamebox.Recordset.BOF Then
Exit Sub
Else
compnamebox.Recordset.MoveNext
End If
Loop
End If
componentlist.Clear
Call populatecomponentcombobox
End Sub
 
Ok, you should really look up how to use a listbox.. but here's some code

Code:
    Dim X
    Dim strSelected
    X = componentlist.ListIndex
    strSelected = componentlist.List(X)

keep in mind that the data in your list box is like an array. You need to get the listindex of the item so you can get the data at that point.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top