DBApprentice
On Error GoTo AWF *****:
- Local time
- Today, 18:20
- Joined
- Dec 24, 2018
- Messages
- 150
Hey folks!
I have been working on the Save_Click event of my form and I have raised error 2046 sometimes, saying the SaveRecord wasn´t available. I have used RuralGuy´s advice to work this around:
But then I found a similar command:
Unfortunately they both raise the same error sometimes.
Studying a little more and I now understand Access will save the form automatically if I close the form or move to next/previous record and that´s why you have to check the Dirty state before actually saving it to avoid raising the error - please correct me if I am wrong.
That made me wonder what would be the correct code to avoid raising errors and save the record through the form and also canceling dirty records. I am thinking maybe I could embed Undo code on the cmdExit_Click and cmdClearForm_Click events - my forms do not have arrows to move fwd or bwd, but do have a "cmdEdit" button to enable the mandatory fields to be changed.
So the bottom line is given there are two similar commands ("DoCmd.Save" and "DoCmd.RunCommand acCmdSaveRecord"):
1. How to correctly code to save a form´s changed information to the underlying query?
2. Besides, am I right to assume I can add Undo on the ClearForm_Click()?
I appreciate all the help!
I have been working on the Save_Click event of my form and I have raised error 2046 sometimes, saying the SaveRecord wasn´t available. I have used RuralGuy´s advice to work this around:
Code:
If Me.Dirty Then Docmd.Save acForm End If
Code:
DoCmd.RunCommand acCmdSaveRecord
Studying a little more and I now understand Access will save the form automatically if I close the form or move to next/previous record and that´s why you have to check the Dirty state before actually saving it to avoid raising the error - please correct me if I am wrong.
That made me wonder what would be the correct code to avoid raising errors and save the record through the form and also canceling dirty records. I am thinking maybe I could embed Undo code on the cmdExit_Click and cmdClearForm_Click events - my forms do not have arrows to move fwd or bwd, but do have a "cmdEdit" button to enable the mandatory fields to be changed.
So the bottom line is given there are two similar commands ("DoCmd.Save" and "DoCmd.RunCommand acCmdSaveRecord"):
1. How to correctly code to save a form´s changed information to the underlying query?
2. Besides, am I right to assume I can add Undo on the ClearForm_Click()?
I appreciate all the help!