Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Apr 2003
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    delete record from listbox (a97)

    I have created a listbox to view/edit the records. I have a button whereby it serves to delete the record from the listbox. How to do that with written codes?Pls help... <img src=/S/crazy.gif border=0 alt=crazy width=15 height=15>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: delete record from listbox (a97)

    You will have to tell us a bit more about your setup.

    1. Does your list box show a list of all records in a table (or query)?
    2. If so, what is the bound column of the list box and to which field in the table (or query) does this column correspond? Is it a unique index in the table (or query)?
    3. Can the user select multiple items in the list box?
    4. Is suppose that by "delete the record from the listbox" you mean that you want to delete the corresponding record from the table (or query). Is that correct?

    If you provide enough information, somebody will be able to help you.

  3. #3
    Star Lounger
    Join Date
    Apr 2003
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: delete record from listbox (a97)

    Im apologized for not providing more information. Alright, to answer your questions :-
    1. Yes, the listbox which i created was unbound and shows a list of all records in a table
    2. in the query table, i indicate all columns in groupby and it correspond with the unique number by search combo which i did not create primary key in my table. So the unique number that i use something like this ;(1,2,3...)
    3. user can only select one items in the listbox because the listbox which i created for easy to do some modify the item when selected
    4. yes, when after inputing some records and found that theres some errors in 1 or 2 records, users are allowed to delete direct from listbox which item is selected.

    I hope you have enough information that I have provide for you as per your request. Please do not hesitate to ask me if you want to know more. Im awaiting for your reply. Thanks for your help and hear from you soon. <img src=/S/compute.gif border=0 alt=compute width=40 height=20>

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: delete record from listbox (a97)

    Sorry, but you can't delete an item from a listbox in A97. What you can do is use code or a query to delete the selected item from the table and then requery the listbox. I didn't understand whether you meant that the table did not have a primary key or the listbox did not contain the primary key. If the former, I don't see how you expect to delete a specific record if you can't identify it with a unique key. If the latter, you can add the primary key field to the listbox, make it the first column in the list, and set the column width of that column to zero.
    Charlotte

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: delete record from listbox (a97)

    To add onto what Charlotte wrote, the unique number you mention must be the first column in the list box; it may be hidden if you like by setting its column width to 0.

    Let's say that:
    <UL><LI>The list box is named lstSelect
    <LI>The command button is named cmdDelete
    <LI>The table is named tblData
    <LI>The unique number field is named ID[/list]The code to be executed when the user clicks the button would look like this:

    Private Sub cmdDelete_Click()
    Dim strSQL As String
    strSQL = "DELETE * FROM tblData WHERE ID = " & Me.[lstSelect]
    CurrentDb.Execute strSQL
    Me.[lstSelect].Requery
    End Sub

    Of course, you must replace cmdDelete, lstSelect, tblData and ID by the names of the comand button, list box, table and field in your database.

  6. #6
    Star Lounger
    Join Date
    Apr 2003
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: delete record from listbox (a97)

    Thanks its works well. cheers! You are really an expert....... <img src=/S/bravo.gif border=0 alt=bravo width=16 height=30>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •