Undo: another question

G

Guest

Hi all,
I wrote a piece of code that undo changes for a form field when
it is filled in with a wrong value (I use the BeforeUpdate event);
it works fine. I have just a final question.

Let's suppose the undo action is the last one.
The next action I do is to press a button that modifies some records.
At this time Access prompts for a message: "the record has been modified
by another user ..." etc. This is pretty annoying.

As far as I understood, Access did not commit yet the undo changes and
is waiting for the focus to move to another field, to commit.
I cannot move focus in the BeforeUpdate event (error 2108).

The question is: is there a way to automatically force Access to commit
undo changes without any user action (e.g., via coding)?

Just for completeness I include the code:
------------------------- start of code ------------------------
Private Sub Squadra_BeforeUpdate(Cancel As Integer)
Dim res As Integer

If Not IsNull(Me.Squadra.OldValue) Or Me.Squadra.OldValue <> Me.Squadra Then
res = DLookup("Punteggio", "AnagraficaAtleti", "IDAtleta = " &
Me.IDAtleta)
If res > 0 Then
MsgBox "<<<this is the msg body>>>", vbCritical + vbOKOnly
Me.Squadra.Undo
Cancel = True
End If
End If
End Sub
------------------------- end of code ------------------------

I hope someone can point me in the right direction. Thanks in advance
for any responses.
Roberto
 
D

Dirk Goldgar

rferrari27 said:
Hi all,
I wrote a piece of code that undo changes for a form field when
it is filled in with a wrong value (I use the BeforeUpdate event);
it works fine. I have just a final question.

Let's suppose the undo action is the last one.
The next action I do is to press a button that modifies some records.
At this time Access prompts for a message: "the record has been
modified
by another user ..." etc. This is pretty annoying.

As far as I understood, Access did not commit yet the undo changes and
is waiting for the focus to move to another field, to commit.
I cannot move focus in the BeforeUpdate event (error 2108).

The question is: is there a way to automatically force Access to
commit
undo changes without any user action (e.g., via coding)?

Just for completeness I include the code:
------------------------- start of code ------------------------
Private Sub Squadra_BeforeUpdate(Cancel As Integer)
Dim res As Integer

If Not IsNull(Me.Squadra.OldValue) Or Me.Squadra.OldValue <>
Me.Squadra Then res = DLookup("Punteggio", "AnagraficaAtleti",
"IDAtleta = " &
Me.IDAtleta)
If res > 0 Then
MsgBox "<<<this is the msg body>>>", vbCritical + vbOKOnly
Me.Squadra.Undo
Cancel = True
End If
End If
End Sub
------------------------- end of code ------------------------

I hope someone can point me in the right direction. Thanks in advance
for any responses.
Roberto

Although Access has "undone" the control, it still thinks the record is
dirty. Try undoing the form itself, as well as the control:

Me.Squadra.Undo
Me.Undo

I'm not sure this will work in a control's BeforeUpdate event, but it's
worth a try.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Data Integrity Violation 1
Subform Undo button in masterform 2
Undo Changes 2
Error 2115 with cancel and undo? 1
Property not found 17
No current record? 10
Clearing a textbox after Cancelling 3
Undo button fails 9

Top