• delete record from listbox (a97)

    • This topic has 5 replies, 3 voices, and was last updated 22 years ago.
    Author
    Topic
    #387047

    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… crazy

    Viewing 0 reply threads
    Author
    Replies
    • #674016

      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.

      • #674348

        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. compute

        • #674354

          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.

        • #674446

          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:

          • The list box is named lstSelect
          • The command button is named cmdDelete
          • The table is named tblData
          • 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.

    Viewing 0 reply threads
    Reply To: delete record from listbox (a97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: