View Full Version : Deleting a selected row from listbox


faz88
04-07-2008, 02:46 PM
Hi, How do i delete a selected row from a list box? My listbox has the rowsource type of table/query. When i try to delete the selected row all the data is removed and shows the query that was used to populate the listbox details instead

ajetrumpet
04-07-2008, 06:58 PM
your initial RS of the box should be an SQL statement, so, in order to dynamically delete just one line, you will have to write some code. Here's an example block (using a listbox with one column):

Current listbox (RS = "SELECT table.field FROM table") - name = "Listbox1":
person1
person2
person3

On click of a button:me.listbox1.rowsource = "SELECT table.field FROM table " & _
"WHERE table.field <> forms!formName!listbox1"
me.listbox1.requery

faz88
04-08-2008, 08:54 AM
i tried the above code but its still deleteing all the records in the listbox and not the one i select....

ajetrumpet
04-08-2008, 07:28 PM
if you're trying to reference any column of the listbox other than column 0 (the first one), you have to use the column syntax with the listbox reference, like this:WHERE table.field <> forms!formname!listbox.column(#)