Delte Record Button = OnClick; Ask "Sure to delete?"

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear Helpers,

I am absolutely new at VisualBasic Coding....

I have form when I want to add a button that deletes the current record. It
is very easy; I used Button wizard and chose a procedure for record deletion.

BUT - I want the user to be prompted whether he/she is sure about deleting
the record.

Can you help me somebody?

Procedure which Access offered:
-------------------------------------------------------------------
Private Sub DeleteRcd_Click()
On Error GoTo Err_DeleteRcd_Click


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

Exit_DeleteRcd_Click:
Exit Sub

Err_DeleteRcd_Click:
MsgBox Err.Description
Resume Exit_DeleteRcd_Click

End Sub
-----------------------------------------------------------------------------
 
....still me....

On this form I have few fields which input is required. When I push the
"Delete record button" while not all the required items are input (contain
Null value(s)), delete is not done

as MSAccess asks first to enter values to all the required fields.

How to do it so that

the record is deleted before all these fields entered? (I don't want to
bother the user if he/she makes a mistake and want to begin entering the
record.)
 
Hi,

If there are required fields that have not been entered then the record has
not been saved. You can only delete a record after it has been saved to the
table.

To get the user to confirm they wish to delete a record use code like:

If MsgBox("Delete the current record are you sure?", _
vbYesNo + vbExclamation + vbDefaultButton2, _
"Please Confirm") = vbYes Then
DoCmd.RunCommand acCmdDeleteRecord
End If

This will display the message box with yes and no buttons. If yes is
pressed then the current record will be deleted.
The focus will be on the no button so the user will have to make a conscious
decision to press Yes.


--
HTH

Mark Phillipson

Free Add-Ins at; http://mphillipson.users.btopenworld.com/
 
Back
Top