OnCurrent fires twice for subform

J

James Bennett

Has anyone experienced the OnCurrent event firing twice
for a subform and figured out why this is happening? I
have a main form with a subform on it that are linked via
the Master/Child property. The data for both forms comes
from linked tables to another Access db. (not the cause
from what I can tell). There is no code in either form
except for the Debug.Print "OnCurrent for" & Me.Name
statement I have in both OnCurrent events.
This outputs:
OnCurrent for TestSub
OnCurrent for TestSub
OnCurrent for TestMain

Any ideas would be greatly appreciated.
 
J

John Viescas

James-

That's just the way it works. In fact, Access loads and opens the subform
first. If you have the Access 97 Orders sample database, you can see the
sequence of events by opening the ShowEvents sample form. The events occur
in this sequence (latest event at the top):

BillTo_GotFocus - outer form
BillTo_Enter - outer form
ProductID_GotFocus - subform
ProductID_Enter - subform
[Subform] Form_Current
ProductID_LostFocus - subform
ProductID_Exit - subform
ProductID_GotFocus - subform
ProductID_Enter - subform
[Subform] Form_Current
ProductID_LostFocus - subform
ProductID_Exit - subform
[Subform] Form_ApplyFilter
Form_Current - outer form
Form_Activate - outer form
Form_Resize - outer form
Form_Load - outer form
Form_Open - outer form
ProductID_GotFocus - subform
ProductID_Enter - subform
[Subform] Form_Current
[Subform] Form_Resize
[Subform] Form_Load
[Subform] Form_Open

Notice that Access opens the subform first (bottom of the list) and even
puts the focus on the first control. It then opens the outer form and
applies the filter from the first outer record to the subform. It's not as
inefficient as it might first appear - Access doesn't actually load the
entire recordset of the subform until after the Apply Filter - an
optimization that was introduced in 95 or 97.

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
http://www.deanforamerica.com/site/TR?pg=personal&fr_id=1090&px=1434411
 

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

Top