Results 1 to 4 of 4
  1. #1
    P5C768 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2009
    Location
    Denver, CO
    Posts
    95

    Problem using rst.delete

    I'm trying to create a form to allow users to select specific inventory and delete it. I can't use a delete query because the ID I am using is not numeric and I would like users to be able to delete individual, selected or ranges of inventory.



    Here is the coding I have so far:

    Code:
    Private Sub Delete_Inv_btn_Click()
        Dim ditem As Variant
        Dim dbCurrInvent As DAO.Database
        Dim rstInv As DAO.Recordset
        Set dbCurrInvent = CurrentDb
        Set rstInv = dbCurrInvent.OpenRecordset("Main_Inventory_tbl")
        If Forms!Delete_Inv_frm!TestID.ItemsSelected.Count <> 0 Then
            For Each ditem In Forms!Delete_Inv_frm!TestID.ItemsSelected
                rstInv.Delete
            Next ditem
        Else
            MsgBox "Nothing was selected from the list", vbInformation
            Exit Sub
        End If
    End Sub
    As far as I can tell, this isn't doing anything. I use similar coding to add records and that seems to work fine.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It looks like you're using a multiselect listbox? In any case, there's no connection between the recordset and the listbox. You'd have to navigate the recordset to the selected record in the listbox and then delete it. What I would do is execute delete SQL within the loop, using the loop variable in the WHERE clause.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    P5C768 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2009
    Location
    Denver, CO
    Posts
    95
    Thanks, I'll give that a try. I thought that was the problem but I wasn't sure how to approach deleting the record other than ret.delete.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem, post back if you get stuck. You can use the Delete method, but you have to navigate the recordset to the desired record. I find the SQL method simpler.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Delete Record; Yes/No
    By mar_t in forum Access
    Replies: 5
    Last Post: 03-10-2011, 07:15 AM
  2. Delete and Update VBA
    By shexe in forum Programming
    Replies: 0
    Last Post: 08-25-2010, 01:44 PM
  3. #delete records
    By supernova122 in forum Access
    Replies: 0
    Last Post: 07-08-2009, 08:41 AM
  4. HELP with Delete Query
    By brown in forum Queries
    Replies: 1
    Last Post: 04-22-2009, 10:11 PM
  5. Add/Delete Button
    By ocemy in forum Forms
    Replies: 1
    Last Post: 03-29-2009, 08:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums