Results 1 to 2 of 2
2002-08-28, 05:07 #1
- Join Date
- Aug 2002
- Thanked 0 Times in 0 Posts
If the user decides to quit (Access 2000)
I want to foresee a case in my code when the usuer issues an order but then suddenly changes his mind and decides to leave.
In this case i want to delete everything he has written up to now.I need some help in this respect and therefore i will have to be more detailed.
So i have a main form called frmMain and a subfrom called frmSubform.On the main form i have 3 buttons, cmdOrder adnCmdInvoice and CmdManual.
On the subfoirm i have a control called Cases and in the AfterUpdate event i have the following function
Private Sub Cases_AfterUpdate()
strSQLBP = "UPDATE Products SET ProductMix = ProductMix - " & Me.Cases & strWhere
Me![Quantity] = Me![cases] * Me![pack]
DoCmd.GoToRecord , , acNext
So, when the customer selects a customer in the main form,immediately a new orderid is opened and the on the subform he selects the
products.On each product the customer has to select the number of cases( cases of fruits). The customer may select different products
to make the order. If the customer decides that the order is full, then he clicks either the button CmdOrder or CmdInvoice,or CmdManual, and then an Order
or an Invoice is opened and printed.
My problem is that if the customer suddenly decides to give up and closes the form, the new order still remains,although false.
SO i want the help in the following respect :
If the customer has selected several products, but didnt press the button CmdOrder or CmdInvoice or CmdManual in the main form, then the code must delete
eveything he has writen up to now,something like that:
DELETE * FROM Orders WHERE orderID = me![OrderID]
II wonder what and where shall i put a code to cancel everything
2002-08-28, 10:45 #2
- Join Date
- Mar 2002
- Thanked 30 Times in 30 Posts
Re: If the user decides to quit (Access 2000)
The problem with code to delete order data is to make sure it is always executed when required. You might call it from a cmdClose command button, or from the OnClose event of the form, but then you must check whether the order has been cancelled. And the code won't run at all if the database crashes, so you may be left with invalid orders anyway.
Two suggestions for another approach:
(1) You might add a boolean field Confirmed to your Orders table. This field will be False by default. Set it to True in the code behind the cmdOrder etc. buttons. Next, create a query based on the Orders table that selects only the records with Confirmed = True. This query will be the basis for other queries, reports etc. You can periodically delete all records with Confirmed = False older than a few days to remove clutter.
(2) You might bind your form and subform to temporary tables, and copy records from these temp tables to the actual tables when the user clicks one of the buttons confirming the order.
Note: it might be a good idea to update the stock info *after* the order has been confirmed.