Inserting text boxes on demand with macros

So I was trying to make fields on demand on a form, from Libreoffice base
As far as I know is using this code or some similar:

textbox = ThisComponent.createinstance(“com.sun.star.???”)
thisComponent.drawPage.add(textbox)

I tried many ways, even once I created a text box that was some kind of invisible, it was on the form navigator but it wasnt on the form somehow (besides it hadnt any option to set size or position)

Why don’t you set textboxes invisible and set it visible when it is needed? Creating a box also needs to get the right position, the right width and height, the right connection to data source…

I usually would do that, but considering I want to have up to 200 or 300 text boxes I’m not sure if thats it’s a good idea have them permanently on the form even being invisible (I guess… maybe invisible fields wont affect performance?)

You would loose more performance when creating textboxes while the form is opened.

By the way: What kind of data do you want to work with? When reading ‘300’ It couldn’t be something like a database for Bibliography, Addressbock or so.

Here some code I have found in a German Makro Guide, but had been written for Dialogs.

textbox = ThisComponent.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
with texztbox
.setPopertyValue("positionX", 15)
.setPropertyValue …

https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1awt.html
might help here
https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1awt_1_1UnoControlFormattedFieldModel.html
shows the details for the allround fieeld “Formatted Field”

I’m trying to create a big grid to display (and later print) data but without the limitations of the premade grid from Libreoffice, editable size, font, fields, even colors from row or columns. I already made some smaller grids but not that big

It returns the error

BASIC runtime error.
An exception occurred
Type: com.sun.star.lang.ServiceNotRegisteredException
Message: unknown service: com.sun.star.awt.UnoControlFixedTextModel.

So ThisComponent isn’t the right place in the form for connecting.
You will need xray to get the right place.
Something like ThisComponentDrawpage.Forms.getByName(“Your Form”)
will allow to connect to the form of the form document you have opened.

It has to be the right component, otherwise it returns that the method “createInstance” doesnt exist.
The error is on the service, the only service that worked was the “com.sun.star.form.component.TextField” but that creates an intangible field