Windows
Version 22H2 Build 19045.5608
LO
Version: 24.8.5.2 (X86_64) / LibreOffice Community
Build ID: fddf2685c70b461e7832239a0162a77216259f22
CPU threads: 2; OS: Windows 10 X86_64 (10.0 build 19045); UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: threaded
I have a form that allows the user to edit certain lookup tables. It consists of 7 main forms, some of which have a hidden control, all with the same name. The following subroutine identifies the main forms with the hidden controls and loads their names into a list box.
Sub mcrUpdateFrmLst(objEvent As Object)
Dim objFrms As Object
Dim objFrm As Object
Dim lstFrms As Object
Dim iintFrm As Integer
Dim astrFrms(0) As String
objFrms = ThisComponent.DrawPage.Forms
lstFrms = objEvent.Source.Model.Parent.getByName("lstFrmsWithHiddenCtls")
iintFrm = 0
For Each objFrm In objFrms
'An error means the ctl doesn't exist in that frm, so skip the next steps.
On Error GoTo EndOfLoop
objFrm.getByName("ctlHidden_FrmData")
'Resume normal error messages.
On Error GoTo 0
Redim Preserve astrFrms(iintFrm)
astrFrms(iintFrm) = objFrm.Name
iintFrm = iintFrm + 1
EndOfLoop:
Next objFrm
lstFrms.StringItemList = astrFrms
End Sub
Using errors to determine whether something exists or not always strikes me as using a hammer to do the job of a screwdriver. Is there a more elegant way of doing this?
More generally, is there a way to use code to search through the controls in a form and identify which ones are list boxes, which ones are hidden controls, etc?