Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Delete record process

Status
Not open for further replies.

THWatson

Technical User
Apr 25, 2000
2,601
CA
Using Access 2003 (2000 format)

Behind a Delete button on a form, I have the following code
Code:
Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click

Select Case MsgBox("  Do you really wish to" _
                   & vbCrLf & "   DELETE this record?" _
                   & vbCrLf & "" _
                   & vbCrLf & "This cannot be undone!" _
                   , vbYesNo Or vbExclamation Or vbDefaultButton1, "Delete check")
    Case vbYes
        GoTo DeleteProcess
    Case vbNo
        Exit Sub
End Select
    
DeleteProcess:
    DoCmd.SetWarnings False
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
    DoCmd.SetWarnings True

Exit_cmdDelete_Click:
    Exit Sub

Err_cmdDelete_Click:
    MsgBox Err.Description
    Resume Exit_cmdDelete_Click
    
End Sub

Is there any reason that should no longer work? It used to work.

If I select the record, and click on "Delete Record" from the Edit menu, it works there...but not in this VBA code.

I tried using coding
Code:
Docmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

That doesn't work either. The message I get is "The Delete command is not available now."


Tom

 
I found the problem.

It had to do with setting focus to a subform before attempting to delete the record.

Tom
 
although not your problem you may want to get rid of

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

this is no longer supported and will cause problems use runcommand.
 
Yep, I did that too.

I removed those lines and inserted
Code:
DoCmd.RunCommand acCmdDeleteRecord

Thanks.

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top