debsamguru
Member
- Local time
- Today, 19:58
- Joined
- Oct 24, 2010
- Messages
- 82
Hi,
I have a form NewOrderF which is called as follows:-
A new order header record is created in the OrderHeaderT on opening the NewOrderF. I have a button, Close, which should delete anything that has been created if clicked. I have 'On Dirty' fields set up but if I simply click on the Close button, I would expect the order header record to get deleted but it doesn't. Here is my code - what am I doing wrong?
All I want to do is be able to clean up the records if the order is cancelled.
Thanks
I have a form NewOrderF which is called as follows:-
Code:
Private Sub NewOrderBtn_Click()
On Error GoTo Error_NewOrderBtn_Click
Dim CustomerInputID As Variant
CustomerInputID = Me.CustomerID
DoCmd.OpenForm "NewOrderF", , , , , , CustomerInputID
Exit Sub
Error_NewOrderBtn_Click:
MsgBox "Error Number: " & Err.Number & " Description : " & Err.Description, , "Error - CustomersF - NewOrderBtn"
Exit Sub
End Sub
A new order header record is created in the OrderHeaderT on opening the NewOrderF. I have a button, Close, which should delete anything that has been created if clicked. I have 'On Dirty' fields set up but if I simply click on the Close button, I would expect the order header record to get deleted but it doesn't. Here is my code - what am I doing wrong?
Code:
Private Sub Close_Click()
On Error GoTo Error_Close_Click
Dim POIDInput As Variant
Dim OrderLinesCount As Integer
Dim Response As Integer
Dim query As String
Dim db As dao.Database
Dim rs As dao.Recordset
Set db = CurrentDb
POIDInput = Me.ID
MsgBox "POID = " & POIDInput
If Me.SaveBtn.Enabled = True Then
If msaved = True Then
DoCmd.Close
Exit Sub
End If
Else
'Nothing has been entered at all - delete the inserted header record'
query = "DELETE * FROM OrderHeaderT WHERE ID = " & POIDInput
db.Execute (query), dbFailOnError
Set db = Nothing
DoCmd.Close
msaved = False
Exit Sub
End If
If POIDInput <> "" Or Me.CustomerID <> "" Then
Response = MsgBox("This will delete the whole Order. Do you want to cancel this Order?", vbYesNo, "Cancel Order")
If Response = vbYes Then
query = "SELECT * FROM OrderItemsT WHERE POID = " & POIDInput
Set rs = CurrentDb.OpenRecordset(query)
If Not rs.BOF And Not rs.EOF Then
rs.MoveFirst
While (Not rs.EOF)
rs.Delete
rs.MoveNext
Wend
End If
rs.Close
Set rs = Nothing
query = "DELETE * FROM OrderHeaderT WHERE ID = " & POIDInput
db.Execute (query), dbFailOnError
MsgBox "Order Cancelled", , "Cancel Order"
Set db = Nothing
DoCmd.Close
msaved = False
End If
Else
DoCmd.Close
End If
Exit Sub
Error_Close_Click:
MsgBox "Error Number: " & Err.Number & " Description : " & Err.Description, , "Error - NewOrderF - Close"
Exit Sub
End Sub
All I want to do is be able to clean up the records if the order is cancelled.
Thanks