How to?

tico78

Registered User.
Local time
Today, 01:39
Joined
Mar 10, 2003
Messages
14
I have placed on the form a button to "Delete A Record". My problem is that there is no warning message that you are about to delete a record, i.e "Are You Sure You Want To Delete This Record". I'm sure there as a way I can build this in, I just don't know how. need help
thanks
 
On the OnClick() of your button put a bit of code like this:

If MsgBox("Are you sure you wish to delete this record?", vbQuestion + vbYesNo, "Deleting Current Record") = vbYes Then
DoCmd.RunCommand acCmdDeleteRecord
End If
 
I use something like this before deleting a record from a button:

Code:
Private Sub Command2_Click()
On Error GoTo Err_Command2_Click

Dim continue
    
continue = MsgBox("This action will delete a record. Are you sure you want to continue?",vbYesNo, "Warning!")
    Select Case continue
        Case vbYes
            DoCmd.OpenQuery "YourDeleteQueryName"
        Case vbNo
            Cancel = True
     End Select
        

Exit_Command2_Click:
    Exit Sub

Err_Command2_Click:
    MsgBox Err.Description
    Resume Exit_Command2_Click
    
End Sub

HTH
Carmen
 
Here's the way I do it....

Dim DB As DAO.Database
Dim strSQL As String
Dim Msg, style, Response

Msg = "Delete the Current Record" & Chr(10) _
& "Are you sure?"
style = 36 + vbDefaultButton1

Response = MsgBox(Msg, style)
If Response = vbNo Then
Exit Sub
Else
Set DB = CurrentDb

strSQL = "DELETE * FROM [MyTable] WHERE [MyID]= " & Me!MyID
DB.Execute strSQL
Me.Refresh
MsgBox "Record has been deleted"
End If

DB.Close
Set DB = Nothing
 

Users who are viewing this thread

Back
Top Bottom