run python as macro in base on push of button

I am new to libre office. I have done some programming in vb.net.
I am trying to write a program where there are two forms one main and one sub. I have created the forms and now want to extract data from table on the press of a button and populate the sub form with selected data. I can write the sql but how to have it to populate is my problem. I have looked at a lot of videos on Libre office but found what I am looking for. After executing the sql some data will have to be manipulated before displaying in the fields in the sub form. Can anyone point me in the right direction please.
BVer

Hello,

Need more info as what is being done is not clear. On the surface it hardly seems a macro is necessary. When you state two forms are you referring to internal forms? What is the connection between forms? Are you selecting on the main form which determines something to be displayed on sub form? If a macro is necessary, is Python your only choice? Basic? A little more clarity on exactly what is being done please.