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

How to Keep Access From Automatically Saving Form Changes

100+
P: 121
This is king of urgent. I am in the middle of system testing and having problems.

I have a form where users can update a Mater List of Values. I have a Save, Delete, Add-New, and Forward and Backward buttons.

But when the users make changes to a record and then hit forward or hit "Add-New', it automatically saves the records. I thought about putting in an 'undo' command with the forward and backward buttons, but that undoes even changes that got saved.

Is there a way to keep access form automatically saving changes, or can I fix this problem some other way?

Thanks for any help.
May 7 '07 #1
Share this Question
Share on Google+
12 Replies


NeoPa
Expert Mod 15k+
P: 31,347
You have posted this in the Articles section. I am moving it to the Access forum.

MODERATOR.
May 7 '07 #2

MMcCarthy
Expert Mod 10K+
P: 14,534
This is king of urgent. I am in the middle of system testing and having problems.

I have a form where users can update a Mater List of Values. I have a Save, Delete, Add-New, and Forward and Backward buttons.

But when the users make changes to a record and then hit forward or hit "Add-New', it automatically saves the records. I thought about putting in an 'undo' command with the forward and backward buttons, but that undoes even changes that got saved.

Is there a way to keep access form automatically saving changes, or can I fix this problem some other way?

Thanks for any help.
Try putting this in ...

Expand|Select|Wrap|Line Numbers
  1. If Me!Dirty Then ' should only be true for unsaved changes
  2.    ' put undo command here
  3. End If
Mary
May 7 '07 #3

100+
P: 121
Try putting this in ...

Expand|Select|Wrap|Line Numbers
  1. If Me!Dirty Then ' should only be true for unsaved changes
  2.    ' put undo command here
  3. End If
Mary

Thanks - but do I put this in the "ON Dirty..." for the field, or for the form itself?
Or do I put in the code for the button?

Thanks again
May 7 '07 #4

MMcCarthy
Expert Mod 10K+
P: 14,534
Thanks - but do I put this in the "ON Dirty..." for the field, or for the form itself?
Or do I put in the code for the button?

Thanks again
Put it where you want it to be triggered. If you want it on the previous and next command buttons then put it there.
May 7 '07 #5

100+
P: 121
Put it where you want it to be triggered. If you want it on the previous and next command buttons then put it there.

Thanks. I put it in the code for the next button, but it is still not keeping the saved changes. Is it wrong for me to be using the Undo Changes command? Should I be doing something else

This is the code now:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Add_Record_Click()
  2. On Error Resume Next
  3.  
  4. If Me!Dirty Then
  5.     DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
  6. End If
  7.  
  8.     DoCmd.GoToRecord , , acNewRec
  9.  
  10.  
  11. End Sub

Thanks again for all the help
May 8 '07 #6

MMcCarthy
Expert Mod 10K+
P: 14,534
Thanks. I put it in the code for the next button, but it is still not keeping the saved changes. Is it wrong for me to be using the Undo Changes command? Should I be doing something else

This is the code now:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Add_Record_Click()
  2. On Error Resume Next
  3.  
  4. If Me!Dirty Then
  5.     DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
  6. End If
  7.  
  8.     DoCmd.GoToRecord , , acNewRec
  9.  
  10.  
  11. End Sub

Thanks again for all the help
How are you saving the changes?
May 8 '07 #7

100+
P: 121
How are you saving the changes?

Here is the save code I have:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Record_Click()
  2. On Error GoTo Err_Save_Record_Click
  3. Dim Save_Response As String
  4.  
  5.  
  6. Save_Response = MsgBox("You Are About To Save This Record.  Do You Want To Continue?", vbQuestion + vbApplicationModal + vbYesNo, "Save Record?")
  7.  
  8. If Save_Response = vbYes Then
  9.     DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  10. Else
  11.     If Save_Response = vbNo Then
  12.         DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
  13.     End If
  14. End If
  15.  
  16. Exit_Save_Record_Click:
  17.     Exit Sub
  18.  
  19. Err_Save_Record_Click:
  20.     Resume Exit_Save_Record_Click
  21.  
  22. End Sub

Is there a different way I should/could be executing the save of these records?

Thanks again for all the help
May 8 '07 #8

MMcCarthy
Expert Mod 10K+
P: 14,534
Here is the save code I have:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Record_Click()
  2. On Error GoTo Err_Save_Record_Click
  3. Dim Save_Response As String
  4.  
  5.  
  6. Save_Response = MsgBox("You Are About To Save This Record.  Do You Want To Continue?", vbQuestion + vbApplicationModal + vbYesNo, "Save Record?")
  7.  
  8. If Save_Response = vbYes Then
  9.     DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  10. Else
  11.     If Save_Response = vbNo Then
  12.         DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
  13.     End If
  14. End If
  15.  
  16. Exit_Save_Record_Click:
  17.     Exit Sub
  18.  
  19. Err_Save_Record_Click:
  20.     Resume Exit_Save_Record_Click
  21.  
  22. End Sub

Is there a different way I should/could be executing the save of these records?

Thanks again for all the help
No I just find it very strange that undo would undo a saved record
May 8 '07 #9

Denburt
Expert 100+
P: 1,356
First the record handler should be handled in the forms before update event this will make sure you can prevent the record from saving or allow this record to be saved..
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.    Save_Response = MsgBox("You Are About To Save This Record.  Do You Want To Continue?", vbQuestion + vbApplicationModal + vbYesNo, "Save Record?")
  3. If Save_Response <> vbYes Then
  4. Me.Undo
  5. End If
  6. End Sub
  7.  
  8. Private Sub SaveIt_Click()
  9.     DoCmd.RunCommand (acCmdSelectRecord)
  10.     DoCmd.RunCommand (acCmdSaveRecord)
  11. end Sub
  12.  
Also use RunCommand instead of menu items. You did not post any code for what you are using to go to a new record so I don't understand why or how MS Access can or would undo the previous saved changes. Show us what you are using to go to the new record.
May 8 '07 #10

100+
P: 121
I appreciate all the help.

So here is where it stands now:

My code for the Save Button looks like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Record_Click()
  2. On Error GoTo Err_Save_Record_Click
  3. Dim Save_Response As String
  4.  
  5.  
  6. Save_Response = MsgBox("You Are About To Save This Record.  Do You Want To Continue?", vbQuestion + vbApplicationModal + vbYesNo, "Save Record?")
  7.  
  8.     If Save_Response = vbYes Then
  9.         DoCmd.RunCommand (acCmdSelectRecord)
  10.         DoCmd.RunCommand (acCmdSaveRecord)
  11.     Else
  12.             If Save_Response = vbNo Then
  13.                 Me.Undo
  14.             End If
  15.     End If
  16.  
  17. Exit_Save_Record_Click:
  18.     Exit Sub
  19.  
  20. Err_Save_Record_Click:
  21.     Resume Exit_Save_Record_Click
  22.  
  23. End Sub

The code for the Before Update for the form looks like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  
  3.     'If MsgBox("Changes Have Been Made To This Record." _
  4.         '& vbCrLf & vbCrLf & "Do You Want To Save These Changes?" _
  5.         ', vbYesNo, "Changes Found") = vbYes Then
  6.             'DoCmd.Save
  7.         'Else
  8.         If Me.Dirty Then 
  9.             DoCmd.RunCommand acCmdUndo
  10.         End If
  11.     'End If
  12.  
  13. End Sub
The problem I have is that if I put a prompt in the Before Update section, it gives me a prompt even after saving it. If I put it as it is now, the saves don't hold, they still get undone...

Thanks again for everyone's help.
May 8 '07 #11

100+
P: 121
Okay - Never Mind - I am being dense. I get what you are telling me to do - put the confirmation box in the Before Update only, and that will capture all changes.

It works great!

Thanks again!
May 8 '07 #12

Denburt
Expert 100+
P: 1,356
Okay - Never Mind - I am being dense. I get what you are telling me to do - put the confirmation box in the Before Update only, and that will capture all changes.

It works great!

Thanks again!
My pleasure glad we could help.
May 8 '07 #13

Post your reply

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