Problem with Cancel

S

Stefan

Hello,

I've got a SubForm (S2) in another SubForm (S1).

Now the problem. If I change data in S2 and I click outside this SubForm I
want to restore the old values back.

The following code does not work:

Private Sub S2_Exit(Cancel As Integer)
Cancel = True
Me.S2.Form.Undo
End Sub

A second solution was to 'Lock' all the other subforms but as soon I leave
S2 the new data become stored.

What do I wrong.
Stefan
 
A

Arvin Meyer [MVP]

The Access object model uses bound forms. Changed data becomes permanent
upon exit. So the only way to deal with that is to lock the form for
existing records or change the data back if the record is changed. To do
that you would use the Current event in the first case, and the BeforeUpdate
event in the second case. Your existing code should work in the BeforeUpdate
event, but I would add a condition of checking the NewRecord property, or
just turn off the ability to add records.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
S

Stefan

Arvin,
It seems to be working with following code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Cancel = True
Me.Form.Undo
Cancel = False
...
here the code to changing back the button's en disabeling the subform so
that i (or they) must push the button again to change the data.
...
End Sub

As soon I exit the subform the old data reappear

Thanks
 
Top