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

how to code an error msg " are you sure you want to delete?" 1

Status
Not open for further replies.

lr999

Technical User
May 16, 2011
30
US
How to code 'delete scipt' button with a custom confirmation
'Are you sure you want to delete?
 
Code:
Private Sub DeleteButton_Click()

    If MsgBox("Do you really want to delete?", vbOKCancel, "DELETE?" = vbCancel Then Exit Sub

...
Your DELETE Procedure ...
...
End Sub

Kind regards
Mirko
--------------------------------------
>>>>>> ... I am sure, some supportissues are a matter of PEBKAC ... <<<<<
 

I would do it this way:
Code:
Private Sub cmdDelete_Click()

If MsgBox("Are you sure you want to delete?", _
    vbYesNo Or vbQuestion Or vbDefaultButton2, _
    "Delete this?") = vbYes Then
[green]
    'Your Delete logic here
[/green]
End If

End Sub
This way you get the message box with Yes / No buttons, with 'No' as default, so if user just hits Enter, the 'No' will be chosen and the delete will not happen. Just for safety :)

Have fun.

---- Andy
 
@Andy

Yes, you are absolutely right, mine was quick and dirty ;-)

Kind regards
Mirko
--------------------------------------
>>>>>> ... I am sure, some supportissues are a matter of PEBKAC ... <<<<<
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top