Deleting a Record

mrsgwen

Registered User.
Local time
Today, 10:39
Joined
Dec 9, 2008
Messages
26
i have a form that has a add record, delete record and a close button.
When the form is opened it is on the first record, the user can navigate to the record that needs to be deleted using the built in navigation buttons. Once they find the record to be deleted they should be able to hit the delete button and the record is deleted.

here is my code: (this was created using the wizzard, which I have used in many other applications)

Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click

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

Exit_cmdDelete_Click:
Exit Sub
Err_cmdDelete_Click:
MsgBox Err.Description
Resume Exit_cmdDelete_Click

End Sub
 
when the user hits the delete button it should delete the record but instead it gives that error.
 
when the user hits the delete button it should delete the record but instead it gives that error.

What error? I looked back at your original post and it doesn't mention an error. What is the text of the error?
 
I'm so sorry...the error was: DoMenuItem action was cancelled
 
1. Make sure the AllowDeletions of the form is set to YES.

2. You can try substituting the DoMenu items with the more current:

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
 
Yeah, I've changed my code to this and it's still giving me a "RunCommand action was cancelled" error.


Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click
If MsgBox("Are you sure you want to delete this record?", vbYesNo, "Confirm Delete") = vbYes Then
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
End If


Exit_cmdDelete_Click:
Exit Sub

Err_cmdDelete_Click:
MsgBox Err.Description
Resume Exit_cmdDelete_Click
End Sub
 
Can you upload your database (first use compact and repair and then zip the file)?
 
not sure how to do that.....the db is local it is not in SQL.
 
it's very weird bc if I add a record and then use the delete button to delete the new record i added it works fine. but when I go back and navigate to an older record and try to delete it the button doesn't work. i get that error.
 
i'm sorry I'm new to Access 2007 version and I went to tools in Access when I opened the db but I don't see Database Utilities.
 
In 2007, it is slightly different, you go to the Big Round Office button and then select MANAGE > COMPACT AND REPAIR.
 
i think i figured it out......because there are other tables/forms that depends on that table with the list of vehicles.

So, now my question is by look at the mdb do you think there is some kinda code can be written that instead of deleting the record we can choose the "Out of Service" status and then hide that particular vehicle number. Because there is another form that has a drop down with the vehicles listed in it and if we don't some kinda way hide that vehicle it will show up in that drop down list. not sure if any of that made sense to you.
 

Users who are viewing this thread

Back
Top Bottom