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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Q: How to delete currently displayed record?

Status
Not open for further replies.

mikeg8

Technical User
Sep 11, 2003
32
GB
Dumb question no. 243: I have a form displayed which includes a command button to delete the current record. How do I delete the current record? Below is the code I have managed to get so far...

.
.
.
'Deletes the current specimen record (confirmation box)
Private Sub cmd_DeleteThisSpecimen_Click()
On Error GoTo Err_cmd_DeleteThisSpecimen_Click

Dim strPromptText As String, strTitleText As String

strPromptText = "Confirm delete this record?"
strTitleText = "Delete Record"

If MsgBox(strPromptText, vbOKCancel + vbExclamation, strTitleText) = vbOK Then
'delete the current record, somehow!
End If

Exit_cmd_DeleteThisSpecimen_Click:
Exit Sub

Err_cmd_DeleteThisSpecimen_Click:
MsgBox Err.Description
Resume Exit_cmd_DeleteThisSpecimen_Click

End Sub
.
.
.

The bit I'm stuck on is 'delete the current record, somehow!

Any ideas anybody?

Mike

ps Keep any reply simple - because I am!
 
Hi

If MsgBox(strPromptText, vbOKCancel + vbExclamation, strTitleText) = vbOK Then
'delete the current record, somehow!
docmd.RunCommand acCmdDeleteRecord
End If


Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
This is the simplest way

Private Sub DelRec_Click()
On Error GoTo Err_DelRec_Click


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

Exit_DelRec_Click:
Exit Sub

Err_DelRec_Click:
MsgBox Err.Description
Resume Exit_DelRec_Click

End Sub

You can only run a Delete Query but lets keep it simple.
 
You guys are fast!

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

8 deletes the record
6 select record (so you dont see a #Deleted message)

You can also use the Microsoft Access constants...

DoCmd.DoMenuItem acFormBar, acEditMenu, acDelete, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, acSelectRecord, , acMenuVer70

Other useful constants are...
1 acCut
2 acCopy
3 acPaste
4 acSaveRecord
5 acRefersh
9 acSelectAllRecords
 
KenReay, zevw and willir

Thanks for the replies, very helpful

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top