LiCann
asked on
Delete Button
Will this be OK for delete button or do I need to change?
Private Sub DeleteButton_Click()
On Error GoTo Err_DeleteButton_Click
If MsgBox("Delete this record?", vbOKCancel) = vbCancel Then
Cancel = True
Else
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Exit_DeleteButton_Click:
Exit Sub
Err_DeleteButton_Click:
MsgBox Err.Description
Resume Exit_DeleteButton_Click
Private Sub DeleteButton_Click()
On Error GoTo Err_DeleteButton_Click
If MsgBox("Delete this record?", vbOKCancel) = vbCancel Then
Cancel = True
Else
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Exit_DeleteButton_Click:
Exit Sub
Err_DeleteButton_Click:
MsgBox Err.Description
Resume Exit_DeleteButton_Click
Cancel = True
only works for those events that passes a cancel argument like before update:
Private Sub MyTextBox_BeforeUpdate(Can cel As Integer)
So
Cancel = True
will not work for the click event.
BTW:
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
are archaic. Instead of those use:
RunCommand acCmdSelectRecord
RunCommand acCmdDeleteRecord
Reference: http://home.clara.net/tkwickenden/
So instead the code would be:
Private Sub DeleteButton_Click()
On Error GoTo Err_DeleteButton_Click
If MsgBox("Delete this record?", vbOKCancel) = vbOk Then
RunCommand acCmdDeleteRecord
End If
Exit Sub
Err_DeleteButton_Click:
MsgBox Err.Description
End Sub
only works for those events that passes a cancel argument like before update:
Private Sub MyTextBox_BeforeUpdate(Can
So
Cancel = True
will not work for the click event.
BTW:
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
are archaic. Instead of those use:
RunCommand acCmdSelectRecord
RunCommand acCmdDeleteRecord
Reference: http://home.clara.net/tkwickenden/
So instead the code would be:
Private Sub DeleteButton_Click()
On Error GoTo Err_DeleteButton_Click
If MsgBox("Delete this record?", vbOKCancel) = vbOk Then
RunCommand acCmdDeleteRecord
End If
Exit Sub
Err_DeleteButton_Click:
MsgBox Err.Description
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If MsgBox("Delete this record?", vbOKCancel) <> vbOK Then
Exit Sub
Else
Currentdb.Execute "DELETE * FROM YourTAble WHERE YourID=" & Me.YourIDField
Me.Requery '/to refresh the recordset
End If
I'd try to avoid the DoMenuItem where possible ...