Link to home
Start Free TrialLog in
Avatar of pcsettles
pcsettlesFlag for United States of America

asked on

On Current event runs twice on subform.

Hello-
  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?
Avatar of nico5038
nico5038
Flag of Netherlands image

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.

Nic;o)
Avatar of Jeffrey Coachman
pcsettles,

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!
:)

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.

jjafferr
EE Cleanup Volunteer
jjafferr,

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)

jaffer
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 !

Nic;o)
Thanks guys, you made my job easier :o)
Avatar of pcsettles

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of nico5038
nico5038
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
pcsettles

Please reply to the Experts to get further help.

thank you

jjafferr
EE Cleanup Volunteer