Results 1 to 2 of 2
  1. #1
    cbuechner is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Jan 2021
    Posts
    60

    Delete last record of a table

    Im trying to delete just the last record of the table of they chose no. The table is tbl_Deposit.

    Private Sub Command19_Click() DoCmd.RunCommand acCmdSaveRecord


    Me.Requery
    Dim ROA As Recordset

    Dim Answer As Integer

    Set rs = CurrentDb.OpenRecordset("Last_Deposit")
    Answer = MsgBox("Confirm Deposit of" & " " & "$" & rs.Amount & " " & "from" & " " & rs.From, vbQuestion + vbYesNo + vbDefaultButton2, "Message Box Title")

    If Answer = vbYes Then

    DoCmd.SetWarnings False
    DoCmd.OpenQuery "Append_Deposit"
    DoCmd.SetWarnings True
    Forms!Ledger.Requery
    MsgBox "Deposit Added"

    Else

    Set SR = CurrentDb.OpenRecordset("tbl_Deposit")
    SR.FindLast
    SR.Delete
    MsgBox "Deposit Deleted"

    End If

    End Sub
    Im new to this, and learning as I go.

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Your code is trying to delete a recordset, which probably doesn't work. Probably a few other issues as well, such as the lack of criteria in the find method and not testing for "no match" before trying to edit/delete anything found. Either calling a delete query in your code or opening the recordset for edits or creating delete sql in code would work. If the records are shown in a form, navigating to the last record would be the best of all IMO.

    Lastly, trying to modify a record using any find method is risky if the records are not explicitly ordered by you. You should not rely on their positions as seen in an open table.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Delete a record from a table
    By UT227 in forum Programming
    Replies: 6
    Last Post: 11-11-2020, 12:51 PM
  2. Replies: 10
    Last Post: 12-29-2019, 01:32 AM
  3. Replies: 1
    Last Post: 08-04-2016, 01:41 PM
  4. Delete FIRST record from a table.
    By anupludra in forum Access
    Replies: 4
    Last Post: 03-17-2015, 06:44 PM
  5. delete table record with VBA
    By msasan1367 in forum Access
    Replies: 6
    Last Post: 07-07-2013, 11:29 AM

Tags for this Thread

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