Form document: Detect focus change between forms by macro

@Villeroy , great job!

Thanks to all participants for a very interesting topic!
The attached example is based on the approach suggested by @Villeroy in this topic, using the FormController object. The macros from Module2 are from @Villeroyā€™s example.

After opening the FormFocus form, you need to click the Start button. After that, events of getting focus by top-level forms will be tracked. The ID field (if it exists in the form) is taken when the form gets focus.

Macros should also work in Standalone form. To process the subforms, you need to slightly modify the SetFormControllerListener macro code.

FormFocus.odb (36.2 KB)

1 Like

Seems to me this solution is exactly @ALO_Michael is looking for.

Have opened the example. There is set onFocus to every control, not only to the form. if there is any other macro planned for onFocus of a control it will be lost.
There must be a event for forms only. Navigationbar at the bottom of the forms register this event and change from form ton subform without any focus event of all of the controls ā€¦

Thank you @Ratslinger,

No, up to now there is no solution Please refer also to the reply from @RobertG.
What I do not understand: Jumping between the grey and both orange parts (Forms / TableControl), the content in the navigation bar changes showing the actual record number etc. So there must be an event signalizing such changes to LibreOffice.

Thank you very much @sokol92!

I started the .odb and pressed the start button. After that, the info (green fields) for form ā€œERPā€ are shown. Thatā€™s fine!
Iā€™m not sure, that I used the START-button correctly; here it hides the navigation bar, which should not happen in the final solution. If I didnā€™t misunderstand the actual version, for the following issues Iā€™d need enhancements:

  • Info after changes in form ā€œOutgoingā€ are not shown so far.
  • Info after changes in form ā€œProviderā€ are not shown so far.
  • Scrolling through the form ā€œProviderā€ should not reset the START-Button.
  • The START-Button should not be necessary. This means, jumping through the three forms should trigger the macro code directly.
    Do you think, this is possible?

I will prepare a new version taking into account your wishes no later than tomorrow.

That event triggers ā€œBefore Record Changeā€ and then ā€œAfter Record Changeā€

Version 3.
FormFocus3.odb (37.2 KB)

3 Likes

Thanks a lot @sokol92, looks perfect! I have to understand your solution and to transform it into my application; this may take longer than tomorrow due to other obligations. After that, Iā€™ll come back to you.
Thank you so far!

Thanks again,

Iā€™m trying to understand the macros:

  • Am I right that in you3 FormFocus3.odb only the macros ā€œModule3ā€ are actual for your solution? If so, Iā€™d delete Module1 and Module2 for my version.
  • In the code "Module3) I found Sub DocFormLoaded(oEvent) and Sub DocFormUnLoaded(oEvent), both are triggered in Menu > Extras > Customize > Event. The Form itself has Macros DocFormLoaded and FormUnLoaded (ref. picture):

    these makros I donā€™t find. Are you OK to delete both connections?

Hello!

Module3 uses the getParentObject function from Module2.

I apologize - these are traces of my experiments. You need to remove the handlers of these events using the appropriate button.

No need for any apology at all. I am so grateful for your amazing support!
I have reduced the database FormFocus 20230226 E.odb (16.8 KB) for my further research.

  • During testing, I have been a bit confused: After opening the form, the green field are empty (same in your version). Would it be possible, to set the focus on start to the first form (here ā€œProviderā€) and to disply information in green fields from there?
  • ā€œModule3ā€ lines 87ā€¦90 seem to be empty, but deleting the lines, seems to produce an error.

Thank you!

Letā€™s try changing one macro:

Sub DocFormLoaded(oEvent)
  Dim oDoc, oForm
  oDoc=oEvent.Source
  If oDoc.CurrentController.isFormDesignMode Then Exit Sub
  SetFormControllerListeners oDoc
  oForm=oDoc.DrawPage.Forms.getByName("Provider")
  FillMainForm oForm
  oDoc.CurrentController.getControl(oForm.getByName("fmtID")).setFocus
End Sub

For any listener in Basic, we must create macros to handle all possible events, regardless of whether we are going to respond to these events.