[Base] get name of control table when pushing a button

Hello

Tried to find it on the web, but couldn’t up to now…

I have a form document in Base (let’s say MyFormDocument) in which I have a main form (MyMainForm) and two subforms (MySubform1 and MySubform2).
In each of the subform, I have a control table, with same configuration (the two point to the same data table, but have each a different filter), named so MyControltable1 and MyControltable2.
Finally, I have a push button.

edit: I attach an example odb document: example.odb

What I would like is, when I select a row in a control table, and then press the push button, to be able to get (in a macro) the name of the control table. I’ve begun to formalize this in the following macro:

Sub MyMacro
	oForm = ThisDatabaseDocument.FormDocuments.getByName( "MyFormDocument" )
	oForm = oForm.Component.DrawPage.Forms.getByName("MyMainForm")
	' now, how can I get the name of subform/table control I selected a row in before pressing the push button?'
End Sub

I’ve seen some pieces of code that deal with for eg. oEvent.source.model.name, but this provide the name of the push button…
Is there a property/method associated to MyMainForm (or other…?) that would provide the last “active” control/focus/cursor position before pressing the button?
Or when clicking in the table control, generate a global (?) variable that stores the clicked row to be used then in a sub launched by the push button? (then, how to get control of the “current” control table without having to name it?)
Is all that impossible…?

Maybe to provide the objective of all of this: I’ve built a planning by replicating the same table control in many subform, each subform being filtered on a specific date. In each table control, so, I’ve been able to populate with all the events that are planned (or occured) on a specific date. From that, I would like to click on a specific event (meaning a specific row in the control table of a specific day, so subform), press a button, and be transfered to another form document that provide details on the selected event (indeed, in the planning, only few details are providing).

Thanks a lot for any track to resolve this need!

Hello,

There is nothing to determine something which was last selected without some elaborate scheme.

Not certain why you even need two different table controls simply because they have a different date in the filter. This can be selected and applied using a Date control and a simple macro to apply the date.

As for the record selected, you can have a button press to open a new form based upon the record selected. There is a sample doing this in my answer on this post → Base macro that opens a new/clean record in another form.

This can be applies whether using my single table selection or your multiple table set up.

Edit 2020-02-13:

Have a sample for you. Used your original sample. All code for this (it is not much) was placed in ‘Module2’ so as not to mix with your code. Included a small routine to resize the form windows (currently a bug) and positioning can be added. For that see this post → Adjust size and placement of a form in Base

Added two new forms. “Sample1” uses no macros and simply displays in a subform the details of the selection in the main form. Your side-by-side is retained as each is on its’ own main form. You can add date filtering to each form if wanted.

The second form added, “Sample2”, does use the macro method in the above link. Each button calls the same routine but since each button is on a different form and ‘oEvent’ passes this information, the same macro is called by each button. When the button is pressed the currently selected record in the associated table control will open in your “Events” form. This means you only have one “Events” form opened at a time since the code always uses the same form.

Gave you options here. Not going to say what you should use. Totally up to you as you know the direction you are going in.

Sample ---- MultiSelect.odb

Thanks for answer. Well noted that my need is not easy to solve.

I implemented in two different table controls because I need to have the two boxes appearing in the same time (as in a planning/calendar view, where all days of one months are visible). If I put the two table controls in the same form (thus, with same data source), is is still possible to apply a different filter in the same time so that different information is displayed in the same time in the two table controls? Is it possible to apply a filter on a date field in a table control, which won’t echo on the whole form?

I’ll have a look on your link for the button.

@greb,

Will work up an example later today and post. It will incorporate the linked answer to present record in a new form.

@Ratslinger,

Thank you very much for your help, and file example.
Indeed, both solutions work but for my case, i think the second one is more suitable, as I can’t display information of an event under the corresponding day box (in terms of place). So assigning a button to each day box, calling each the same routine, will be the more appropriate option, even if it requires some place on the form. Thanks!

Thanks also for the (re)sizing subs. Actually it produced quite strange things (maximized window with the tool bar in middle of the window…). Maybe due to different configuration (I am on Lubuntu 18.04 and LO 6.3.0.4)… Anyway, it provides me some good pieces of code that I will surely be able to use in other situation!