I have writen this code for the " child form " in my order main form, for on delete event , this code work fine,
problem is when choosing " No option " at the time of
execution then the delete process stops successfuly. but
other buttons on my main form stop functioning. like delete button for my main form.
may be because i'm using the cancel event at the end of my code for on delete event.
please give me any advise.
here is the code.
Private Sub Form_Delete(Cancel As Integer)
Dim title As String
Dim dbs As Database
Dim wsp As Workspace
Dim D As Recordset
Dim Z As Recordset
title = "BackOffice 1.0.3"
If MsgBox("Record will be deleted. Want to delete (Y/N)?", vbYesNo, title) = vbNo Then GoTo err_prih
Set dbs = CurrentDb
Set wsp = DBEngine.Workspaces(0)
wsp.BeginTrans
'check if this order number of my main form exist in invoice table.
Set D = dbs.OpenRecordset("select * from Invoice_main where Invoice_ref=" & Parent!OrderID, dbOpenDynaset)
If D.RecordCount > 0 Then
MsgBox ("Invoice have been issued on this order, deletion is not possible, please delete the invoice first."
, vbCritical, title
wsp.Rollback
dbs.Close
wsp.Close
GoTo err_prih
End If
' here i'm checking products in the reseved table using the Order Number in the main form and Product number in the child form.
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 reserved product found for this order."
, vbCritical, title
Else
Z.delete
wsp.CommitTrans
Z.Close
dbs.Close
wsp.Close
End If
MsgBox ("Record have been deleted"
, vbExclamation, title
Exit Sub
err_prih:
Cancel = True
Exit Sub
End Sub
Look forward to any advise.
Thanks in Advance
problem is when choosing " No option " at the time of
execution then the delete process stops successfuly. but
other buttons on my main form stop functioning. like delete button for my main form.
may be because i'm using the cancel event at the end of my code for on delete event.
please give me any advise.
here is the code.
Private Sub Form_Delete(Cancel As Integer)
Dim title As String
Dim dbs As Database
Dim wsp As Workspace
Dim D As Recordset
Dim Z As Recordset
title = "BackOffice 1.0.3"
If MsgBox("Record will be deleted. Want to delete (Y/N)?", vbYesNo, title) = vbNo Then GoTo err_prih
Set dbs = CurrentDb
Set wsp = DBEngine.Workspaces(0)
wsp.BeginTrans
'check if this order number of my main form exist in invoice table.
Set D = dbs.OpenRecordset("select * from Invoice_main where Invoice_ref=" & Parent!OrderID, dbOpenDynaset)
If D.RecordCount > 0 Then
MsgBox ("Invoice have been issued on this order, deletion is not possible, please delete the invoice first."
wsp.Rollback
dbs.Close
wsp.Close
GoTo err_prih
End If
' here i'm checking products in the reseved table using the Order Number in the main form and Product number in the child form.
Set Z = dbs.OpenRecordset("select * from Reserve where (OrderID=" & Parent!OrderID & "
If Z.RecordCount <= 0 Then
MsgBox ("No reserved product found for this order."
Else
Z.delete
wsp.CommitTrans
Z.Close
dbs.Close
wsp.Close
End If
MsgBox ("Record have been deleted"
Exit Sub
err_prih:
Cancel = True
Exit Sub
End Sub
Look forward to any advise.
Thanks in Advance