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

Cancel command won't undo all changes made to a form listing multiple records

100+
P: 105
Hello all,

i have a continuous form that displays about 1000 records and opens when I click a button. When the form opens, the user has the option of checking a checkbox that is located beside each record. The checkbox is labeled "Move" (for moving multiple records at a time to another year). Of course, the checkbox is set as a control "moveRecord" on a table that the query is pulling from. So if the user checks one record, then clicks to another record and checks it as well, the first record is automatically saved. If the user decides to check 10 or 20 records, then decides, "OOPS, i may have made some mistakes, i want to cancel!"

i run into a problem....

I have a button on the form that says "cancel." However, if the user clicks that button, the only record that cancels is the last checkbox that was checked. I want all of the checkboxes to disappear when the user opens up the same form again. As it stands right now, the 19 or so other checkboxes still remain as saved into the table.

Please help! Thank you in advance!

I've tried multiple things even the ON DIRTY execute...here's what I have now

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdCancel_Click()
  2. On Error GoTo errHandle
  3. Dim intProcced As Integer
  4.  
  5. 'Warn the user that any information entered will be lost, then if the user responds that it is
  6. 'ok, erase the record and close the form
  7.  
  8. intProcced = MsgBox("Warning: Any changes made or any information entered will not be saved.", vbOKCancel, "Warning")
  9.     If intProcced = 2 Then
  10.         Exit Sub
  11.     End If
  12.  
  13. DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer1X
  14.  
  15. DoCmd.Close
  16.  
  17. Exit Sub
  18.  
  19. errHandle:
  20. If Err.Number = 2046 Then
  21.     DoCmd.Close
  22.     Exit Sub
  23. Else
  24.     'Print the error message and send an email to Administrator
  25.     SendErrorMsg "cmdCancel_Click on frmEnterNewFeeder", Err.Number, Err.Description
  26.     MsgBox Err.Description
  27. End If
  28. Exit Sub
  29.  
  30. End Sub
Jan 11 '08 #1
Share this Question
Share on Google+
8 Replies


Rabbit
Expert Mod 10K+
P: 12,365
Please do not double post your questions, your other thread will be deleted.
Jan 11 '08 #2

Rabbit
Expert Mod 10K+
P: 12,365
Once you change records, it is automatically saved and the changes are committed and can not be undone. You have two options. One is to not use a dynaset and save the entire recordset's changes when needed. This I do not recommend, too many complications. The second is to run an update query that sets all the checkboxes to false if they click cancel.
Jan 11 '08 #3

100+
P: 105
Please do not double post your questions, your other thread will be deleted.
It's not a double post, read it all the way through before making comments.
Jan 14 '08 #4

100+
P: 105
Hey thanks for your tip Rabbit...

I modified my code to look like this....

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdCancel_Click()
  2. On Error GoTo errHandle
  3.  
  4. Dim intProcced As Integer
  5.  
  6. 'Warn the user that any information entered will be lost, then if the user responds that it is
  7. 'ok, erase the record and close the form
  8.  
  9. intProcced = MsgBox("Warning: Any changes made or any information entered will not be saved.", vbOKCancel, "Warning")
  10.     If intProcced = 2 Then
  11.         Exit Sub
  12.     End If
  13.  
  14. If Me.Dirty = True Then
  15.     DoCmd.SetWarnings False
  16.     DoCmd.OpenQuery "qryMoveFeedersFalse"
  17.     DoCmd.SetWarnings True
  18.     DoCmd.Close
  19.     Exit Sub
  20. Else
  21.     DoCmd.SetWarnings False
  22.     DoCmd.OpenQuery "qryMoveFeedersFalse"
  23.     DoCmd.SetWarnings True
  24.     DoCmd.Close
  25.     Exit Sub
  26. End If
  27.  
  28. errHandle:
  29. If Err.Number = 2046 Then
  30.     DoCmd.Close
  31.     Exit Sub
  32. Else
  33.     'Print the error message and send an email to Administrator
  34.     SendErrorMsg "cmdCancel_Click on frmEnterNewFeeder", Err.Number, Err.Description
  35.     MsgBox Err.Description
  36. End If
  37.  
  38. Exit Sub
  39.  
  40. End Sub
Jan 14 '08 #5

Rabbit
Expert Mod 10K+
P: 12,365
It's not a double post, read it all the way through before making comments.
The only difference I saw was you figured out that once you change records, it is automatically saved and the changes are committed and can not be undone.
Jan 14 '08 #6

Rabbit
Expert Mod 10K+
P: 12,365
This part is redundant. There's no need to check for Dirty.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdCancel_Click()
  2. If Me.Dirty = True Then
  3. DoCmd.SetWarnings False
  4. DoCmd.OpenQuery "qryMoveFeedersFalse"
  5. DoCmd.SetWarnings True
  6. DoCmd.Close
  7. Exit Sub
  8. Else
  9. DoCmd.SetWarnings False
  10. DoCmd.OpenQuery "qryMoveFeedersFalse"
  11. DoCmd.SetWarnings True
  12. DoCmd.Close
  13. Exit Sub
  14. End If
  15.  
Jan 14 '08 #7

100+
P: 105
This part is redundant. There's no need to check for Dirty.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdCancel_Click()
  2. If Me.Dirty = True Then
  3. DoCmd.SetWarnings False
  4. DoCmd.OpenQuery "qryMoveFeedersFalse"
  5. DoCmd.SetWarnings True
  6. DoCmd.Close
  7. Exit Sub
  8. Else
  9. DoCmd.SetWarnings False
  10. DoCmd.OpenQuery "qryMoveFeedersFalse"
  11. DoCmd.SetWarnings True
  12. DoCmd.Close
  13. Exit Sub
  14. End If
  15.  
What is the person opens the form, makes NO changes and then clicks cancel.
Jan 14 '08 #8

Rabbit
Expert Mod 10K+
P: 12,365
What is the person opens the form, makes NO changes and then clicks cancel.
Well, the thing is that the query runs no matter what happens. If they make no changes and click cancel, it unchecks all the boxes. If they make a change and click cancel, it unchecks all the boxes. So either way, it unchecks all the boxes.
Jan 14 '08 #9

Post your reply

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