OnCurrent Event Executes Multiple Times

  • Thread starter Thread starter paul.m.henderson
  • Start date Start date
P

paul.m.henderson

Hi,

I've got a form in an ADP with one subform where the Form_Current (of
the main form) event executes three times. This is causing some
locking errors for us, and I was hoping someone would be able to shed
some light on why this might be happening? Thanks!
 
Also,

Here's the event execution log for the form:

Form_Open
Form_Activate
Form_Current
Form_Activate
Form_Current
Form_Current

Thought that might help. Thanks in advance for any help.
 
You've probably already seen this, but posting just in case:

The Current event occurs when the focus moves to a record, making it the
current record, or when the form is refreshed or requeried.



Does this happen when you open the form or when you work with (enter /
change) data, or move between records?

Do you have any "setfocus" or "refresh" or "requery" in your code behind the
form?
 
I get this activity when the form opens. Not sure if it would happen
when moving between records as this form is designed to only show one
record each time it's opened.

As for the SetFocus, Refresh, Requery questions; we do have a couple of
those, however, none of them occurr in the Activate or Current events.
Thanks!
 
any SetFocus, Refresh, Requery in Form_Load or Form_Open?

check for same in the subform code...
 
Hi Paul,

This seems to be a common occurence for main/sub form combinations; I
experienced it a lot. I cannot prove it but suspect it has something to do
with the focus moving back and forth between the main and sub forms. I did
once track down that code I included in some other event also fired the On
Current event but I cannot remember the exact circumstances.

The only remedy I can offer is to suggest that you include a switch at the
form module level along the lines of Private mbinOnCurrentDue as Boolean. The
very first lines of code within the On Current event test this switch and
cause an immediate exit if it is false thus preventing duplication. The last
line of code obviously sets the value to false. The difficult part is
setting the initial value to true. If you want I can dig back through some
code and find out how I did it.

Regards,

Rod
 
Hi again.

I've just delved into some old code and found one example. My memory
however has let me down; there was a main/sub form involved but it was
another synchronized continuous form that was experiencing multiple On
Current events. As Lolik has quite astutely suggested it was a Requery in
the form's On Load event that was one cause of the multiple On Current events
and I used the switch concept to program round it - in fact I
programmatically switched On Current off until On Load had completed.

Regards,

Rod
 
I'd much rather fix the root cause, but since I can't seem to do that I have
had success by using the timer. I restrict the event from firing within .5
seconds of its last run.

The first line of my OnCurrent event is ...

If Timer > lLastOnCurrentTimer + 0.5 Then GoTo Exit_Sub

The last line is ...

lLastOnCurrentTimer =Timer
 
I am not seeing the previous part of this thread, so please ignore these
comments if they are not relevant.

The suggestion to use the Timer does not seem attractive. There are *lots*
of negative side effects to the timer. But more significantly, someone
stepping through the records in a form can certainly be moving faster than 2
records per second.

A better solution might be to declare a form level variable to hold the
primary key value of the current record. If it's the same number as last
time, don't run the code again.

In the General Declarations of the form's module:
Private mvarID As Variant

In Form_Current:
If (Me.[ID] = mvarID) OR (IsNull(Me.[ID]) AND IsNull(mvarID)) Then
Else
mvarID = Me.[ID]
'Put the code that must not repeat in here.
End If
 
Quite relevant! I didn't think of using the PK. That is better.

There are negative side effects of the timer? Perhaps I mispoke. I'm using
the results of the Timer command (seconds after midnight, or whatever it is)
not the Form's OnTimer.



Allen Browne said:
I am not seeing the previous part of this thread, so please ignore these
comments if they are not relevant.

The suggestion to use the Timer does not seem attractive. There are *lots*
of negative side effects to the timer. But more significantly, someone
stepping through the records in a form can certainly be moving faster than 2
records per second.

A better solution might be to declare a form level variable to hold the
primary key value of the current record. If it's the same number as last
time, don't run the code again.

In the General Declarations of the form's module:
Private mvarID As Variant

In Form_Current:
If (Me.[ID] = mvarID) OR (IsNull(Me.[ID]) AND IsNull(mvarID)) Then
Else
mvarID = Me.[ID]
'Put the code that must not repeat in here.
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

David Mueller said:
I'd much rather fix the root cause, but since I can't seem to do that I
have
had success by using the timer. I restrict the event from firing within
.5
seconds of its last run.

The first line of my OnCurrent event is ...

If Timer > lLastOnCurrentTimer + 0.5 Then GoTo Exit_Sub

The last line is ...

lLastOnCurrentTimer =Timer
 

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

Back
Top