listbox.selectedItem at form load

Hello,
Embarrasing - Am in need of L plates…

Win10, Lo6.4.5.2 HSQL2.51

I have a listbox which toggles taxrate after ItemStatusChanged, works ok, however can not figure out the macro for the forms onload event to read the selected value ?

listboxname = lstTaxIncExl
SELECT COALESCE ( “rate” || '% ’ || “txtype”, “txtype” ) “TYPE_PERCENT”, “sid” FROM “tblTaxRates”

Sub togglefields(oEvent)
Dim sTax As Integer
sTax = oEvent.Source.SelectedItem
If sTax = 0 Then
  
    rem hide exclusive, show inclusive
    
oFormMain = ThisComponent.Drawpage.Forms.getByName("MainForm")
oFormSub = oFormMain.getByName("TaxIncExl")

	oFormMain = ThisComponent.Drawpage.Forms.getByName("MainForm")    	
	oFormSub = oFormMain.getByName("TaxIncExl")

ocontrol01= oFormSub.getByName("TaxInclusive")
ocontrol01.enableVisible = true  

ocontrol02= oFormSub.getByName("TaxInclusiveLabel")
ocontrol02.enableVisible = true 

ocontrol03= oFormSub.getByName("TaxExclusive")
ocontrol03.enableVisible = false 

ocontrol04= oFormSub.getByName("TaxExclusiveLabel")
ocontrol04.enableVisible = false
	
ocontrol05= oFormSub.getByName("ttlinclusive")
ocontrol05.enableVisible = false

ocontrol06= oFormSub.getByName("ttlexclusive")
ocontrol06.enableVisible = true

  
 End If
 
 If sTax > 0 Then        
   rem hide inclusive
   
oFormMain = ThisComponent.Drawpage.Forms.getByName("MainForm")
oFormSub = oFormMain.getByName("TaxIncExl")

ocontrol01= oFormSub.getByName("TaxInclusive")
ocontrol01.enableVisible = false  

ocontrol02= oFormSub.getByName("TaxInclusiveLabel")
ocontrol02.enableVisible = false 

ocontrol03= oFormSub.getByName("TaxExclusive")
ocontrol03.enableVisible = true 

ocontrol04= oFormSub.getByName("TaxExclusiveLabel")
ocontrol04.enableVisible = true
	
ocontrol05= oFormSub.getByName("ttlinclusive")
ocontrol05.enableVisible = true

ocontrol06= oFormSub.getByName("ttlexclusive")
ocontrol06.enableVisible = false

End if

end sub

How can I get the form to show the correct fields when calling the form?
Thanks for your thoughts

Hello,

It appears you are opening a form at a given record. It is also that the SQL for the list box is generating a string.

Edit: COALESCE seems OK. End edit.

Best approach may be to simply get the data right from the record. See answer bu @JohnSUN in this post → Get table cell value from Form.

Couple of notes. The code deals with form and sub form. Possibly you only need form. The column you need (based on what you provided) is rate. Also, instead of getString you may need getValue. You can then use that value for your code.

@Ratslinger, thanks for that!