Can a number of controls be created in a macro. The macro is called by a control on a form. Mostly text boxes required.
Thank you for any help. Please if it’s possible to create them, a brief explanation would be great .
In 15 years using Base, I’ve never encountered the need to generate form controls programmatically. If this is about hiding and showing certain attributes, you should hide and unhide form controls as needed.
The Form
surely is inserted into a DrawPage
of a “higher” model.
FormControls
may behave different in Writer/Calc/...
I now assume it’s a Writer document.
I rarely used DB forms, and dind’t for years now. Therefore I will not post concerning the DataBase/Form/Something aspects.
However, the insertion of complex content into a Writer or Calc or (?..) model is a common task.
The attached example demonstrates for the Writer case.
disask97584_InsertFormControlByUserCode.odt (31.5 KB)
You will, of course, need in addition to add the new FormControl
to your Form
.
This may be done by a line like
myForm.insertByIndex(myForm.Count, nextTextBoxControl)
where myForm
is the variable pointing to your chosen Form
or to the Form
containing the control from which you called the macro or to a newly created Form
…
… …
Editing 2023-10-29
I should have started with
- It can be done in principle as shown in the attachment.
- I cannot imagine a realistic use-case.
This makes me feel better as It seems it can be done. Thankyou
Yes the form and controls are used in the Macro, BUT how is the creation done. I can’t find a method. Even a look at your writer method might help.
Creation of WHAT?
How the new FormControl
and the ControlShape
are created and combined is demonstrated in my example. Concerning the assignment of a new control to a form I completed my answer meanwhile. Do you now also want to create a new Form
?
Well, if it helps, that’s fine. BUT if you don’t want to run the code in a Writer context, you should eventually tell what kind of DrawPage (parent of the Form) you are talking of and HOW you GOT the Form
into which you want to insert your new controls.
As I already mentioned I’m all but an expert in DB forms. I will now leave it at that.
Sorry for any misunderstanding. No I don’t want another form. I just want help with the coding to make it happen. Your example showed me a document with a button, that when clicked seem to create a text box. Although it might have made it Visible…
Just seen your latest post. the form is a standard Base form. On it one of the buttons runs the macro, In that macro I read and write info to the form. I also want to create other controls, like your writer page showed.
dim oform as object,ofield as object,ofield2 as object | |
---|---|
oForm = ThisComponent.Drawpage.Forms.getByName(Form) ‘Get Form’ | |
oField = oForm.getByName(Entry) ‘Get access to field’ | |
oField2 = oForm.getByName(Warning) ‘Get access to field’ | |
— | — |
myForm control has no “InsertbyIndex” component.
insertByIndex
isn’t a component, but a method supplied by the interface XIndexContainer which in turn needs to be “exported” by a service. In this case the service is com.sun.star.form.component.Form (in short the Form
service) supported by the form “object” you created or found in the DrawPage. The object itself isn’t shown in the view in this case. But without it you can’t (e.g.) establish a connection to a DataBase.
You can’t insert any object into a FormControl
.
You need to insert … See above.
The new attachment should as well show how it can be done in principle - and why I regard this as completely useless.
disask97584_InsertFormControlByUserCode_Variant.odt (31.8 KB)
After all a newly created FormControl
needs to get assigned (sometimes lots of) properties in a sensible way to be usable for its purpose. If a user is expected to do this in interactive mode - why shouldn’t yeh also do the simple first steps in that context?
I will now edit my first answer to get this more clear, and will not return then to this thread again.
Thankyou for your time and effort. All is working