• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 824
  • Last Modified:

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?
0
pcsettles
Asked:
pcsettles
  • 4
  • 4
  • 3
  • +1
2 Solutions
 
nico5038Commented:
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)
0
 
Jeffrey CoachmanCommented:
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!
:)

0
 
jjafferrCommented:
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
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
Jeffrey CoachmanCommented:
jjafferr,

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

All points to nico5038
;)
0
 
jjafferrCommented:
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
0
 
Jeffrey CoachmanCommented:
If it's ok with nico5038, then it's fine with me as well
:)
0
 
nico5038Commented:
The proposed split is fine with me. :-)

Thanks for cleaning jaffer !

Nic;o)
0
 
jjafferrCommented:
Thanks guys, you made my job easier :o)
0
 
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?
0
 
nico5038Commented:
A Sum() is placed in an unbound field in a header or a footer like:
=Sum([fieldname to sum])

Nic;o)
0
 
Jeffrey CoachmanCommented:
OK,

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
    Else
        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
0
 
jjafferrCommented:
pcsettles

Please reply to the Experts to get further help.

thank you

jjafferr
EE Cleanup Volunteer
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now