On Current event runs twice on subform.

  I have a main form with several tab control pages.  One of the pages has a subform on it.  Both the main form and the subform have some code triggered by the On Current event.  When I move from one record to another on the main form, the On Current code for the subform executes once, then executes again, then the On Current code for the main form executes once.  When I move from one record to another on the subform, the On Current code for the subform executes once only.  The On Current code for the subform simply checks on the caption value of a button on the main form and then sets a couple of properties on a control on the subform.  Any suggestions why the On Current code for the subform is running twice?
Who is Participating?
nico5038Connect With a Mentor Commented:
A Sum() is placed in an unbound field in a header or a footer like:
=Sum([fieldname to sum])

Will probably be the same reason as the double processing of the report. As a Sum() can be placed in a header Access will have first to process all rows to determine a sum and when this is "known" after the last line it can't "return" but will have to put the otal in the header and process the rows again.
Just make sure that your OnCurrent code doesn't interfere with the "normal" processing by changing the mainform's current record or a mainform requiry as that might give an infinite loop.

Jeffrey CoachmanMIS LiasonCommented:

As a side bar, you should also note that when you open a Main Form that contains a Subform, the On Current Event of the subForm fires before the current event of the Main form!

Not looking for any points, just thought you'd find that interesting!

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
    Split: nico5038 {http:#16634960} & boag2000 {http:#16883195}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

EE Cleanup Volunteer
Jeffrey CoachmanMIS LiasonCommented:

Please remove me from the split. my post was an interesting note.

All points to nico5038
Hi Jeffrey

I did read your note
"Not looking for any points, just thought you'd find that interesting!"
before I placed my recommendation, but I found your comment very valuable,
and since the author didn't close the question a month earlier, so chances are s/he was still looking for an answer,
thus your comment was properly placed, and deserves points too.

I still stand by my recommendation :o)

Jeffrey CoachmanMIS LiasonCommented:
If it's ok with nico5038, then it's fine with me as well
The proposed split is fine with me. :-)

Thanks for cleaning jaffer !

Thanks guys, you made my job easier :o)
pcsettlesAuthor Commented:
Thanks for the comments from nico5038 and boag2000.  The comment from boag2000 verified what was stated in the question, except my situation is that the subform OnCurrent is firing twice, then the main form OnCurrent is firing.  Nico5038 may be on to something.  However, my code certainly does nothing like a Sum() on records in the subform, and as far as I can tell, doesn’t do anything on records in the subform that would change a field on the main form.  However, I will look into this more closely.

At one point I was sure I wrote a very simple test database with a MsgBox triggered by the OnCurrent event on both a subform and the main form.  I remember that it verified that the subform OnCurrent MsgBox was triggered twice, then the main form OnCurrent MsgBox.  Unfortunately, I didn’t save that test database, and when I tried to duplicate it, my second test database has the subform OnCurrent firing once, then the main form OnCurrent as expected.  I will continue to try and find a simple test example where the subform OnCurrent fires twice.

I was surprised that this question did not generate more response.  I had hoped that others had seen this behavior in a simple database form and would be able to give me ideas of where to look or be able to explain in what simple situations the OnCurrent event of a subform will fire twice.

If I ever discover what is causing the OnCurrent event of the subform to fire twice in my application, can someone tell me where I would post the discovery?
Jeffrey CoachmanConnect With a Mentor MIS LiasonCommented:

I did a little research.

The Subform Current event will trigger twice if you have a sub-sub Form synchronized to the subform.

For example
Main Form: tblCustomers
SubForm (on a Tabbed control): tblorders
Sub-SubForm: tblOrderDetails

The form wizard puts code on the subform's Current event (a Requery) to sychronize the sub-sub form to the subform.
(make sense?)

Like so:
    Dim ParentDocName As String

    On Error Resume Next
    ParentDocName = Me.Parent.Name

    If Err <> 0 Then
        GoTo Form_Current_Exit
        On Error GoTo Form_Current_Err
        Me.Parent![frmOrderDetails Subform].Requery '<----Note the REQUERY
    End If

A Requery also triggers the OnCurrent Event.
Thus, the Subform Current event fires the first time when you change records on the main for.
Then the Subform Current event fires the second time when the sub-subform is synchronized to the subform.

If one of your Tabbed controls is a sub form of you subform, this could be causing the problem.

So look for a "requery" somewhere.

Hope this helps as well

Please reply to the Experts to get further help.

thank you

EE Cleanup Volunteer
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.