It works fine but for a little problem - when a new record is inserted in the main form and the form is closed, it always reopens on the tab holding the subform, with focus on the subform first line.
I cannot find a way to force the damned thing to open on the first tab. Any idea?
I’m sure you already tried to change the ActiveControlOnOpen property?
If that didn’t help, then it might be something about the control numbering of your subform. I had this problem a long time ago, but I really cannot remember exactly how to solve it.
When you export the main form as text, where do you find the “subform” ?
Actually the numbering of the controls is not of big interest for Navision. It is actually the order they appear in the text export.
Usually Navision activates the topmost one (If ActiveControlOnOpen is not defined).
Can you just try to “move” the subform control just to the end of the form controls (at the end of the page controls) or to the top?.
Define a new GLOBAL variable “NavTimer” or so, set type to Automation and select the Navision Timer 1.0 from the list provided when clicking the Sub Type and select “Timer” in the classes list, click OK. Show the properties of the new variable and set the “WithEvents” property to YES.
OnOpenFormTrigger:
CREATE(NavTimer);
NavTimer.Interval := 100; // Set Timer to fire after 100ms
NavTimer.Enabled := TRUE; // Enable the timer to fire
Further down (last function in the C/AL code) you find to new functions:
NavTimer::Timer(Milliseconds : Integer)
and
NavTimer::TimerError(ErrorString : Text[1024])
In the first of these two triggers you put the following code:
NavTimer.Enabled := FALSE; // Prevents the timer from firing again
CurrForm.ControlToActivate.ACTIVATE;
The idea behind this is that NAV runs some additional internal code to finanlize the creation of the subform AFTER the OnOpenForm trigger of the main form ran.
But as the timer trigger only fires AFTER NAV returns control to the user, we can be quite sure that the sub form initialization has been finished by then and our ACTIVATE really activates the control we want to have activated.
On the Sales Order properties change the SaveControlInfo to no
This will stop NAV from saving the last control the user was on when they closed the form, and always open the form on the first tab in the first control.
the problem was exactly as Thomas described as well as the solution. Yesterday evening I was too tired and confused to make it work, but to morning I managed to make it work - exactly as Thomas said.
Thank you so much, Thomas. That was very clear, but I’m wondering - the form I was experimenting on is form 42 - Sales Order. Following the opening sequence in debug I saw that, after the code in form 42 OnOpenForm trigger, navision executed code in other linked forms triggers, included my subform.
My subfom has an higer control number than the lines subform but comes first in the form source… which might be the reason because the focus stopped on my subform instead on the lines subform as it normally does?
Might it be because my subform has code to be executed and form 46 has not?
This does not really matter. It must have something to do with the sub form as member of the tab control. When you would try to move the subform out of the tab control, you would see different behavior I guess.
thank you for your suggestion. I’ve tried to implement it, since I hoped it would provide a solution without the use of automation, but I must have been missing something, since it doesn’t work.
Setting the DelayedInsert property of the subform to true will prevent this from occuring and foxus will be maintained on the main form. It has to be appropriate to do this though.