Quick one

peterbowles

Registered User.
Local time
Today, 15:45
Joined
Oct 11, 2002
Messages
163
How do you delete the current record out of a list box

thanks
 
When you say "current record out of a listbox" does the listbox on the form have an AfterUpdate() event that realigns the form's recordsource to the listbox selection?
 
no, it is just placed on a form to show some records
it is not related to the form
 
Personally, in the case you've given, I'd use DAO.

Assuming that the listbox (called lstExample) has two or more columns from the table (tblExample) with the first column (the primay key) being hidden then:

Code:
Private Sub lstExample_AfterUpdate()

    Dim db As DAO.Database, rs As DAO.Recordset
    Dim strSQL As String

    If MsgBox("Are you sure you wish to delete this record?", vbQuestion + vbYesNo, "Example") = vbYes Then
        strSQL = "SELECT * FROM tblExample WHERE ExampleID = " & Me.lstExample.Column(0) & ";"
        Set db = CurrentDb
        Set rs = db.OpenRecordset(strSQL)
        With rs
            .Delete
            .Close
        End With

        db.Close

    End If

End Sub


Also, as an aside, can I suggest that you title your posts with something more descriptive than "easy one", "quick one", etc?
As others come to the forum they are advised to search for posts first to find solutions to their problems and having the results turn up meaningful titles is much more helpful to them. And, for people looking to answer questions it is so much easier to know what a question is about without having to open it - that way, if it said "Access Security Model" I'd know to avoid it like the plague. :p
 

Users who are viewing this thread

Back
Top Bottom