By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,640 Members | 2,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,640 IT Pros & Developers. It's quick & easy.

deleting saved data from a form

P: 49
Hello All,

I currently have an order form, when an item is selected and then an add button is pressed this saves the data orderline within the table, for example half way through the order a customer wanted to cancel the whole order placed, i want to delete everything that had been saved so far for this customer on this current order. Any ideas?

eg. an item is selected then add is pressed, this will save within a tblorder and be displayed on the order form, if for what ever reason clear form or exit is selected i want the form to refresh and the order saved so far to delete. hope this is clear.


Thanks
Jan 27 '08 #1
Share this Question
Share on Google+
8 Replies


puppydogbuddy
Expert 100+
P: 1,923
Hello All,

I currently have an order form, when an item is selected and then an add button is pressed this saves the data orderline within the table, for example half way through the order a customer wanted to cancel the whole order placed, i want to delete everything that had been saved so far for this customer on this current order. Any ideas?

eg. an item is selected then add is pressed, this will save within a tblorder and be displayed on the order form, if for what ever reason clear form or exit is selected i want the form to refresh and the order saved so far to delete. hope this is clear.


Thanks
Try something like this, asssuming that OrderNum is numeric. If it isn't then the syntax needs to be modified.
Expand|Select|Wrap|Line Numbers
  1. Dim strSql As String
  2.  
  3. strSql = "Delete * From tblOrder Where [OrderNum] = " & Forms!frmOrder!OrderNum
  4.  
  5. If Me.Dirty
  6.    Me.Undo
  7. Else
  8.     If DCount("[OrderNum]", "tblOrder", "[OrderNum] = " & Me!OrderNum) > 0 Then 
  9.       CurrentDb.Execute strSql, DbFailOnError
  10.       Me.Refresh
  11.     End If
  12. End If    
Jan 27 '08 #2

P: 49
Try something like this, asssuming that OrderNum is numeric. If it isn't then the syntax needs to be modified.
Expand|Select|Wrap|Line Numbers
  1. Dim strSql As String
  2.  
  3. strSql = "Delete * From tblOrder Where [OrderNum] = " & Forms!frmOrder!OrderNum
  4.  
  5. If Me.Dirty
  6.    Me.Undo
  7. Else
  8.     If DCount("[OrderNum]", "tblOrder", "[OrderNum] = " & Me!OrderNum) > 0 Then 
  9.       CurrentDb.Execute strSql, DbFailOnError
  10.       Me.Refresh
  11.     End If
  12. End If
still no luck...

this is what i had entered within the clear form button:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdclear_Click()
  2. Dim strSql As String
  3.  
  4. strSql = "Delete * From tblOrder Where [tblOrder.orderno] = " & Forms!frmOrderform!txtorderno.Value
  5.  
  6. If Me.Dirty Then
  7.    Me.Undo
  8. Else
  9.     If DCount("[Orderno]", "tblOrder", "[Orderno] = " & Me!Orderno) > 0 Then
  10.       CurrentDb.Execute strSql, dbFailOnError
  11.       Me.Refresh
  12.     End If
  13. End If
  14. ' all the values will become empty for a new order to be entered
  15.     Call Form_Load
  16. End Sub
this is the error I am getting: run time error 2455 invalid reference to the property dirty.
Jan 27 '08 #3

puppydogbuddy
Expert 100+
P: 1,923
still no luck...

this is what i had entered within the clear form button:
Private Sub cmdclear_Click()
Dim strSql As String

strSql = "Delete * From tblOrder Where [tblOrder.orderno] = " & Forms!frmOrderform!txtorderno.Value

If Me.Dirty Then
Me.Undo
Else
If DCount("[Orderno]", "tblOrder", "[Orderno] = " & Me!Orderno) > 0 Then
CurrentDb.Execute strSql, dbFailOnError
Me.Refresh
End If
End If
' all the values will become empty for a new order to be entered
Call Form_Load
End Sub

this is the error i am getting: run time error 2455 invalid reference to the property dirty
It sounds like the Me object is the problem. .....maybe because you have a subform....In any event, try using a fully qualified reference in place of Me....
For example....

If Forms!YourMainiForm!YourSubForm.Form,Dirty then

If this does not work, please provide more details about how your order form is structured.
Jan 27 '08 #4

P: 14
still no luck...

this is what i had entered within the clear form button:
Private Sub cmdclear_Click()
Dim strSql As String

strSql = "Delete * From tblOrder Where [tblOrder.orderno] = " & Forms!frmOrderform!txtorderno.Value

If Me.Dirty Then
Me.Undo
Else
If DCount("[Orderno]", "tblOrder", "[Orderno] = " & Me!Orderno) > 0 Then
CurrentDb.Execute strSql, dbFailOnError
Me.Refresh
End If
End If
' all the values will become empty for a new order to be entered
Call Form_Load
End Sub

this is the error i am getting: run time error 2455 invalid reference to the property dirty
Try just deleting the order without fail on error, and then go to a new record for the form. Order entry is usually implemented using 2 tables - one for order definition (customer, date, etc.) and another for line items. The enrty form is then a form/subform combination. So I'm not sure that what I'm saying will work for your case, since a New Record may not create a new Order No depending on your form. Is there a table(s) behind your form?
Jan 27 '08 #5

P: 49
Try just deleting the order without fail on error, and then go to a new record for the form. Order entry is usually implemented using 2 tables - one for order definition (customer, date, etc.) and another for line items. The enrty form is then a form/subform combination. So I'm not sure that what I'm saying will work for your case, since a New Record may not create a new Order No depending on your form. Is there a table(s) behind your form?
Still no luck, your right i am using two tables..

I have a main menu form which is then linked to my order form. Within this form, in have customer details which is being taken from the customer table. Then the rest of the items are selected from the product table and this is being stored within an order and orderline form.

i am dazzeled. plz help
Jan 27 '08 #6

P: 14
Still no luck, your right i am using two tables..

I have a main menu form which is then linked to my order form. Within this form, in have customer details which is being taken from the customer table. Then the rest of the items are selected from the product table and this is being stored within an order and orderline form.

i am dazzeled. plz help
As puppydogdaddy said, without knowing a lot more about how your forms are designed, it is difficult to say what is wrong. I can say that you should not even be involved in 'dirty', 'refresh', and 'load' type operations just to delete the current record out of an invoicing app. These things are handled automatically, with at most a form requery or a GoTo New Record, besides the delete query.

Do you have a relationship between the Order and OrderLine tables that cascades deletes? Is the Parent/Child link between the form and subform in place? Is the OrderLine subform continuous or single form?
Jan 27 '08 #7

P: 14
Do you have a relationship between the Order and OrderLine tables that cascades deletes? Is the Parent/Child link between the form and subform in place? Is the OrderLine subform continuous or single form?
Do you have answers to these questions?
Jan 28 '08 #8

P: 49
Do you have answers to these questions?

Do you have a relationship between the Order and OrderLine tables that cascades deletes? Is the Parent/Child link between the form and subform in place? Is the OrderLine subform continuous or single form?

Currently i dont have a relationship that allows this to occur, orderline, it is just a table between the orderline and orders.
I have put this in place, so i can have more than order number for one order, so each item that is ordered is given an order number that relates to that order. this is a composite key in the orderline table with customerID. hope this is understanable
Jan 28 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.