Undo: another question

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
Back
Top