Hello,
Most of what you have been asking thus far is already in many samples and/or documents. An excellent reference for macros is OOME by Andrew Pitonyak.
As a bonus..
This is not a game show or contest. Again, another very common solution presented many places across the net & documents.
Setting a list box to a specific item -
Sub SetListBox
oForm1 = ThisComponent.Drawpage.Forms.getByName("MainForm") 'Get Form
oField = oForm1.getByName("txtCustomer")
Doc = ThisComponent
DocCtl = Doc.getCurrentController()
'Get VIEW for listbox
CtlView = DocCtl.GetControl(oField)
CtlView.selectItemPos(1, True)
oField.commit()
End Sub
The index for entries in a list box is relative to 0. Since this list is generated from SQL, the first item is blank and therefore it is needed to be set to 1
. This sub can be run from the Open Document
event of the form.
Since the customer list box also has an event to refresh the ECN list box you can add the setting of the selected item there also. However the item to set there is 0 since the items there are based upon a valuelist which has no blank entry.
To have the subform refresh without using a button is just attaching a simple macro to an event of the listbox upon which it is based -
Sub RefreshSubForm
oForm1 = ThisComponent.Drawpage.Forms.getByName("MainForm") 'Get Form
REM Next two lines only needed because of the way you have constructed form
oField = oForm1.getByName("txtECNList")
oField.commit()
oSubForm = oForm1.getByName("ECNDetails")
oSubForm.reload()
End Sub
It is becoming clear that this project you are putting together is being done piecemeal. As you think of something you patch in a solution. A good example is this form you presented here. It would seem this form may be better off using a table filter for the main form instead of a data table. You should also avoid macros whenever possible which requires you to better understand Base & SQL. If you do choose to use macros you need to spend a great deal of time in learning not just using your language of choice but also the interaction with UNO API (the harder part of the two).