Strange, code failing first time but succeeds the second time its run.

  • Thread starter Thread starter Kjell Harnesk
  • Start date Start date
K

Kjell Harnesk

I have the following code on a button on a main form. I use it to update a
control on a subform based on the values of two other controls both on a
subform of its own.

Forms!Mainform!Subform1![TimV] = Forms!Mainform!Subform2![TimV] *
Forms!Mainform!Subform3![TimV]

The code is on one line only.
The problem is that it fails with the error message "The record has been
changed" Maybe not those exact words because it is translated from the
swedish version of Access. When i cklick the button a second time (or more)
the code runs as expected. What is wrong?

Access 2003 SP2, Win XP Pro SP2.
 
Kjell said:
I have the following code on a button on a main form. I use it to update a
control on a subform based on the values of two other controls both on a
subform of its own.

Forms!Mainform!Subform1![TimV] = Forms!Mainform!Subform2![TimV] *
Forms!Mainform!Subform3![TimV]

The code is on one line only.
The problem is that it fails with the error message "The record has been
changed" Maybe not those exact words because it is translated from the
swedish version of Access. When i cklick the button a second time (or more)
the code runs as expected. What is wrong?

Access 2003 SP2, Win XP Pro SP2.


I'm just guessing here, but it sounds like the subforms have
not completed some sort of operation when the button click
occurs (maybe the Load event or a Requery??).

One way to check this is to place a breakpoint on the
troublesome line and then check each of the subform values
in the immediate/debug window. I'll bet everthing looks
fine and if you just resume execution that it will work.

If my guess is correct, there isn't much you can do to
coordinate these asynchronous processing threads necause VBA
execution runs at a higher priority than form processing and
screen updating. Adding a DoEvents before the line might
make it work some of the time, but there are no guarantees.
One thing that cah be done is to remove that line of code
and use the equivalent expression in the main form text box
(assuming it's unbound).
 
Marshall Barton said:
Kjell said:
I have the following code on a button on a main form. I use it to update a
control on a subform based on the values of two other controls both on a
subform of its own.

Forms!Mainform!Subform1![TimV] = Forms!Mainform!Subform2![TimV] *
Forms!Mainform!Subform3![TimV]

The code is on one line only.
The problem is that it fails with the error message "The record has been
changed" Maybe not those exact words because it is translated from the
swedish version of Access. When i cklick the button a second time (or more)
the code runs as expected. What is wrong?

Access 2003 SP2, Win XP Pro SP2.


I'm just guessing here, but it sounds like the subforms have
not completed some sort of operation when the button click
occurs (maybe the Load event or a Requery??).

One way to check this is to place a breakpoint on the
troublesome line and then check each of the subform values
in the immediate/debug window. I'll bet everthing looks
fine and if you just resume execution that it will work.

If my guess is correct, there isn't much you can do to
coordinate these asynchronous processing threads necause VBA
execution runs at a higher priority than form processing and
screen updating. Adding a DoEvents before the line might
make it work some of the time, but there are no guarantees.
One thing that cah be done is to remove that line of code
and use the equivalent expression in the main form text box
(assuming it's unbound).


How about forcing a requery of subform2 and subform3 before doing the
computation?
 
Back
Top