i have writen this code for On Delete event of my form, which is a child continous form, and this code suppose to delete the record when the del key is pressed.
well problem is when i press " NO " at the moment when the message appears and ask the confirmation for deletion then this code don't stop it still delte the record , how can i solve it , i tried using " cancel = -1 " before the exit sub, And every thing worked out but i found that my other buttons stop functioning. and take lone time to execute and do nothing. just hanged.
,one more thing i have used set warnning to true and false in the before and after deletion event. to avoid displaying the system messages.
here is the code.
On Delete Event
==============
Dim title As String
Dim dbs As Database
Dim D As Recordset
Dim Z As Recordset
title = "BackOffice 1.0.3"
Set dbs = CurrentDb
' here is the problem, when i choose " No " in this message then this event should stop and exit from this sub . but it goes further and delete the record.
If MsgBox("Record will be deleted. Continue(y/n)?", vbYesNo, "BackOffice"
= vbNo Then Exit Sub
Set D = dbs.OpenRecordset("select * from Invoice_main where Invoice_ref=" & Parent!OrderID, dbOpenDynaset)
If D.RecordCount > 0 Then
MsgBox ("There is a record found in Invoice table. Deletion is not possible",vbCritical, title
D.Close
dbs.Close
GoTo err_prih
End If
' checking the records in the reserve table.
i have set this record set to compare the records in Reserve table, if it found then it will be deleted from the Reserve table first then should be delted from my child form, which is bound to another table.
Set Z = dbs.OpenRecordset("select * from Reserve where (OrderID=" & Parent!OrderID & "
AND (pronumber=" & Me.productid.Column(0) & "
", dbOpenDynaset)
If Z.RecordCount <= 0 Then
MsgBox ("No record found in Reserve."
, vbCritical, title
' here record should be delted from the Reserve table then after it should be deleted from my child from.
Else
Z.delete
Z.Close
dbs.Close
End If
MsgBox ("Record have been deleted"
, vbExclamation, title
Exit Sub
err_prih:
Exit Sub
End sub
After Del Confirm
===============
Private Sub Form_AfterDelConfirm(status As Integer)
DoCmd.SetWarnings True
End Sub
Before Del Confirm
================
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
DoCmd.SetWarnings False
End Sub
Please correct me what i'm doing wrong.
thank in advance.
well problem is when i press " NO " at the moment when the message appears and ask the confirmation for deletion then this code don't stop it still delte the record , how can i solve it , i tried using " cancel = -1 " before the exit sub, And every thing worked out but i found that my other buttons stop functioning. and take lone time to execute and do nothing. just hanged.
,one more thing i have used set warnning to true and false in the before and after deletion event. to avoid displaying the system messages.
here is the code.
On Delete Event
==============
Dim title As String
Dim dbs As Database
Dim D As Recordset
Dim Z As Recordset
title = "BackOffice 1.0.3"
Set dbs = CurrentDb
' here is the problem, when i choose " No " in this message then this event should stop and exit from this sub . but it goes further and delete the record.
If MsgBox("Record will be deleted. Continue(y/n)?", vbYesNo, "BackOffice"
Set D = dbs.OpenRecordset("select * from Invoice_main where Invoice_ref=" & Parent!OrderID, dbOpenDynaset)
If D.RecordCount > 0 Then
MsgBox ("There is a record found in Invoice table. Deletion is not possible",vbCritical, title
D.Close
dbs.Close
GoTo err_prih
End If
' checking the records in the reserve table.
i have set this record set to compare the records in Reserve table, if it found then it will be deleted from the Reserve table first then should be delted from my child form, which is bound to another table.
Set Z = dbs.OpenRecordset("select * from Reserve where (OrderID=" & Parent!OrderID & "
If Z.RecordCount <= 0 Then
MsgBox ("No record found in Reserve."
' here record should be delted from the Reserve table then after it should be deleted from my child from.
Else
Z.delete
Z.Close
dbs.Close
End If
MsgBox ("Record have been deleted"
Exit Sub
err_prih:
Exit Sub
End sub
After Del Confirm
===============
Private Sub Form_AfterDelConfirm(status As Integer)
DoCmd.SetWarnings True
End Sub
Before Del Confirm
================
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
DoCmd.SetWarnings False
End Sub
Please correct me what i'm doing wrong.
thank in advance.