Murray Brown
asked on
Access VBA Code to stop data saving to tables
Hi
I have an Access form that was generated using a wizard.
I want to put an "OK" and "Cancel" button on the form so that data
is not commit to the underlying table unless the OK button is used.
So far I have the following code that runs on the click of the "Cancel" button:
One major concern is that the user clicks an arrow button to move to the next record. How do I stop that?
I have an Access form that was generated using a wizard.
I want to put an "OK" and "Cancel" button on the form so that data
is not commit to the underlying table unless the OK button is used.
So far I have the following code that runs on the click of the "Cancel" button:
If Me.NewRecord Then
If Me.Dirty Then
Me.Undo
End If
End If
DoCmd.Close
Where else should I put this or similar code to stop data being saved unless the user clicks the "OK" button?One major concern is that the user clicks an arrow button to move to the next record. How do I stop that?
He meant BeforeUpdate.
Jim.
Jim.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also, if you use Subforms note that Access will always save the Parent data when you move into that subform. If you introduce the suggestions above, the user would be asked to save the data anytime they move into the subform (assuming they've "dirtied" the parent data, of course), so you could run into a situation where you must Delete the parent data if they decide to NOT save the Subform data. AFAIK, there's no way to avoid that other than using temporary tables to base your forms on.
ASKER
Thanks very much
You're welcome.
Set parameter Cancel to True if you don't want the record to be saved.