Form_Current() event is triggered twice in a subform

winshent

Registered User.
Local time
Today, 22:23
Joined
Mar 3, 2008
Messages
162
I have a subform which I have some code in the Current() event. For some reason it gets triggered twice when the main form is opened.

Anyone got ideas as to why this is and how I can trap for it ?
 
Here're a few thoughts...
  • When a form has a subform, the subform loads first and its current event runs. Then the main form loads, runs its current event, and then applies any constraints/filters (LinkMaster and LinkChildFields) and if that causes the subform record to change, which is likely, then the current event on the subform runs again.
  • You can test this behaviour by putting a couple of MsgBoxes in the Form and Subform Form_Open() event handlers and check out the order in which they fire.
  • One option you have, and you start to notice the performance improvement if your subform's table gets big, is programmatically load the subform object AFTER the main form loads. To do this, leave the SourceObject property of the subform control blank at design time, and at runtime, say in the MainForm's Open event handler, set the value of the SourceObject property to the name of the form you want to load into the subform control.
  • This is also a nice way to vastly speed up and simplify forms that have multiple subforms on a tab control. You can make the tab transparent and have just one subform control. Then programmatically change the SourceObject property of the subform control whenever the tab changes.
Hope that helps,
Mark
 
Here're a few thoughts...
  • When a form has a subform, the subform loads first and its current event runs. Then the main form loads, runs its current event, and then applies any constraints/filters (LinkMaster and LinkChildFields) and if that causes the subform record to change, which is likely, then the current event on the subform runs again.
  • You can test this behaviour by putting a couple of MsgBoxes in the Form and Subform Form_Open() event handlers and check out the order in which they fire.
  • One option you have, and you start to notice the performance improvement if your subform's table gets big, is programmatically load the subform object AFTER the main form loads. To do this, leave the SourceObject property of the subform control blank at design time, and at runtime, say in the MainForm's Open event handler, set the value of the SourceObject property to the name of the form you want to load into the subform control.
  • This is also a nice way to vastly speed up and simplify forms that have multiple subforms on a tab control. You can make the tab transparent and have just one subform control. Then programmatically change the SourceObject property of the subform control whenever the tab changes.
Hope that helps,
Mark

Hi Mark

This works really well !! Thanks very much..
 

Users who are viewing this thread

Back
Top Bottom