delete helps.Thanks

racerrunner

Registered User.
Local time
Today, 09:00
Joined
May 29, 2005
Messages
32
Hi all,

Dim vAns As Variant

vAns = MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, "Delete")
If vAns = vbYes Then
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

I'm trying to create a delete function. First, it prompt me whether i want
to delete this record
vAns = MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, "Delete")

However, after i click 'Yes". Another prompt will pop up and ask me whether i want to delete this record. This prompt is not this prompt vAns = MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, "Delete")

I think it is access built-in prompt. my qn is that is there any way to prevent the 2nd prompt from being pop up?

Thank you
 
Before running query, add a line

Code:
DoCmd.Setwarning = False

then when you're done with query,

Code:
DoCmd.SetWarning = True

Cavaet: If you do not turn warnings to true after the query, you will have serious problem that could corrupt your database.

Oh, and your question isnt the first time it has been asked. Use search. You'll find that there has been already several answers.
 
Searching this forum is a great way to discover and learn the answers to your Access programming questions.

Dump the old "DoCmd.DoMenuItem" wizard commands and do it right.

Code:
Private Sub bDelete_Click()
On Error GoTo Err_bDelete_Click
   
    If MsgBox("Are you sure you want to delete the current record?", vbQuestion + vbYesNo, "Delete Current Record?") = vbYes Then
        DoCmd.SetWarnings False
        DoCmd.RunCommand acCmdSelectRecord 'this command might not be needed
        DoCmd.RunCommand acCmdDeleteRecord
        DoCmd.SetWarnings True
    End If

Exit_bDelete_Click:
    DoCmd.SetWarnings True
    Exit Sub

Err_bDelete_Click:
    If Err.Number = 2046 Then 'The command DeleteRecord isn't available now - No records to delete
        DoCmd.SetWarnings True
        MsgBox "There is no record to delete.", vbCritical, "Invalid Delete Request"
        Exit Sub
    ElseIf Err.Number = 2501 Then 'The RunCommand action was canceled
        DoCmd.SetWarnings True
        Exit Sub
    Else
        MsgBox Err.Number & " - " & Err.Description
        Resume Exit_bDelete_Click
    End If
    
End Sub
 

Users who are viewing this thread

Back
Top Bottom