Discussion Locked

Delete DB record

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

hi, i have a VB form linked to a db. i want to be able to delete an existing record (which i have done and it works) but i want to notify the user whether they want to continue with the operation or change their mind. i gather you need a msgbox witha yes/no option on it but when you click no in my program it still deleted the record. what coding do i need to put in after the msgbox to cancel the delete operation.
ghost

5 replies

by timfox

Check and double check your msgbox code and only execute your DELETE command after you are sure that the msgbox returns a yes. If it returns a 'no' - then don't execute your DELETE command. You should be assigning the return value of your msgbox similar to as follows:
dim response as integer
response = msgbox ("Are you sure you want to delete this record?", vbquestion+ vbyesno,"Confirm Action")
'Display result when debugging
msgbox "response was: " & response
if response = 6 then 'is yes =6?
'Insert delete command here
else
msgbox "Record not deleted.", vbinformation, "Action Cancelled"
end if

Does this help?

by mohammad_m_saggaf

Hi,
In the click event of your Delete button but the following code:

Private Sub CmdDel_Click()
Dim Result As Long
Result = MsgBox("You attempt tot delete a record. Are you sure?", vbQuestion Or vbYesNo, "Deleting Record")
If Result = vbYes Then
' Deleting code

' Assuming you use a ADODC data control (ADODC).
Adodc1.Recordset.Delete adAffectCurrent

' Assuming you use a code ADO Recorset object (RSData).
RSData.Delete
End If
End Sub

I hope it helps.

This discussion is closed to new replies.