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

Delete all values in a list box from table 1

Status
Not open for further replies.

lashwarj

IS-IT--Management
Nov 1, 2000
1,067
US
I have two list boxes, one of which stores all values related to a item, then, not visible to the user, I have a list box that stores the value they remove from the list box, how can I get it so when the user clicks the save button it deletes the items in the hidden list box from the tables.

Ex. I have 5 items in my list box the user wants to delete 2 of those items so they double click the item and it is dumped to a hidden list box, so if they save the records are deleted and if they click cancel no changes have been made.
 
lashwarj,

The items in a listbox can be accessed by looping through the lisytbox's ListCount property as follows:

FOR LstCounter = 1 TO .ListBox.ListCount

ENDFOR

Inside the loop you can find out what the value of each line is and find that value in your table and delete it.

Hope that helps,

Stewart
 
but how do i issue a delete on multiple values, the list box may contain 1 or more values, and is it a delete where table = memvar
 
Does the hidden list box have more than one column? If so, which column would you use to search for the record that you want to delete?

You do the deleting one at a time inside the FOR...ENDFOR loop. Something like...

FOR LstCounter = 1 TO .ListBox.ListCount
MyValue = .listbox.list(LstCounter)
LOCA FOR MyField = MyValue
DELETE
ENDFOR

If you had more than one column in the listbox then you would put the column number as a second parameter of List().

Hope that helps,

Stewart
 
Here is the code i made from yours, but it does not delete the values, the LstCounter shows = 2 and I dont know if that is why its not deleting

WITH Thisform.delete_Referral
FOR LstCounter = 1 TO Thisform.delete_Referral.ListCount
DELETE_ID = VAL(Thisform.delete_Referral.list(LstCounter))
LOCATE FOR approval_lk_referal.referral_id = DELETE_ID
DELETE
ENDFOR
ENDWITH
 
lashwarj,

Hmmm.

What do you get in your variable DELETE_ID?

Before running your code, you would need to have SELECTed the alias of the table in which you want to delete records.

I can't see why else it wouldn't work. I'll just go and do a quick test. Anyone else got an idea?

Stewart
 
I found what it was, thank you for your help. It was a stupid mistake on my part

*select table


ha ha ha ha ha I had * it out while testing other code
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top