Simple Delete Command and previous record view

ThunderBolt

Registered User.
Local time
Today, 16:33
Joined
Apr 29, 2003
Messages
25
This is simple, but it has stumped me today. I am adding code to the onclick event on a button, on a form. The button needs to delete the current record and then display the record prior to that on the screen. I would like to have a "are you sure" option and so far i have managed to complie the following code:

Dim intResult As Integer

intResult = MsgBox("Are You Sure You Want To Delete This Record?", vbYesNo)

If intResult = vbYes Then
???
Else
Cancel = True
End If


Exit Sub

The ??? signify the where the code for the delete current record record command should appear. I would be greatful for someone to give me a hint on that please.

I would also appreciate any help on how to revert back to the last record when a record has been deleted i.e the record has been wiped and instead of blank boxes on the form where the record used to be, the previos record now appears.

Thankyou,

Regards Thunderbolt
:confused:
 
Here is what I typically use for a Delete command...
Code:
Private Sub bDelete_Click()
On Error GoTo Err_bDelete_Click
    
    Beep
    If MsgBox("Are you sure you want to delete the current record?", vbQuestion + vbYesNo, "Delete Current Record?") = vbYes Then
        DoCmd.RunCommand acCmdDeleteRecord
        DoCmd.RunCommand acCmdRecordsGoToPrevious 'you shouldn't need this command
    End If
    
Exit_bDelete_Click:
    Exit Sub
    
Err_bDelete_Click:
    If Err = 2046 Then 'The command DeleteRecord isn't available now - No records to delete
        MsgBox "There is no record to delete.", vbCritical, "Invalid Delete Request"
        Exit Sub
    ElseIf Err = 2501 Then 'The RunCommand action was canceled
        Exit Sub
    Else
        MsgBox Err.Number & " - " & Err.Description
        Resume Exit_bDelete_Click
    End If
        
End Sub
HTH
 

Users who are viewing this thread

Back
Top Bottom