Creating a form for a table with a button?

How are you?
I hope you can help?
I have a table and I realize I can make a cell active in the table and go to Data>Forms and I then can add or delete data from the table in calc.
How do I create my own button that will do the same thing? I tried doing a macro and assigning it to that button but I couldn’t get the form to show.
Your help would be greatly appreciated. Thank you.

Every Sheet of the SpreadsheetDocument has a DrawPage which has a FormCollection accessible as .Forms . It is originally empty (.Count=0). As soon as you insert any FormControl somewhere in the sheet, the.Forms container automatically gets a newly created .Forms(0) created which will contain the new FormControl, and will add additionally inserted ones. .
You can also create a Form like in
formComps = CreateUnoService(“com.sun.star.form.FormComponents”) and insert it into the predefined container by (e.g.)
Forms(0)…insertByIndex(1, formComps)
( Inever needed to do so.)

Maybe you misread the question.
I have a table. If I make a cell active in the table I can then go to Data>Forms and calc will create a form of the table that I have active. I then can add or delete information from that table using the form that calc created.
How can I call that form by assigning a macro to a button? Or, simply what must I do to make this happen? I would like a button to call a form that adds and deletes information from a table that I created.

@iwannaapple,

You don’t need any button or macro. You can add to an existing toolbar or create a new toolbar. From menu Tools->Customize... and on the Toolbars tab it is the Form command under Available Commands.

if you intend to use a macro and assign it to a button be aware that there is a problem, the button ‘steals’ the focus from the active cell, and doesn’t have the capa to process or pass on all functions, so macros are partially blocked … you can trigger them ‘manually’ or in the IDE or via shortcut, but you need special tricks to trigger them via button. See: “uno: copy” via the dispatcher does not work when a button has focus and duplicates, and calc: Is there some known issues using button to execute a macro - II ?

Some control models, in specific buttons have a Boolean property .FocusOnClick. If it is set to False, the focus is not taken over. Or did you mean something else by the term “steal”?
(“Of course”, the mentioned property is named differently, and thus misleading in the object editor. The UI is really thoroughly messed up.)

Sub checkButtonTakeFocus(pEvent)
model = pEvent.Source.Model
If model.supportsService("com.sun.star.awt.UnoControlButtonModel") Then
  Print model.FocusOnClick
End If
End Sub

@wannaapple:

Maybe you misread the question. I have a table. If I make a cell active in the table I can then go to Data>Forms and calc will create a form of the table that I have active.

Yes. I misunderstood you due to not having read the question thoroughly enough. Sorry. If you had tagged the question base in the first place I had assumed the actual intention. I woiuld not have posted any comment then, because I generally put base questions aside being too little experienced with the component.

@Lupp,

This is about Calc and has nothing to do with Base or as you have mentioned forms with controls. This is about Data Entry Forms → Form

Hi, @iwannaapple, Post an example, use edit your question and with the clip icon attach the file.

@Ratslinger: Thanks! I missed that. Beginner’s error. I never used this way of entering data into Sheets for decades. How possible? Should have kept silent. Sorry!

BTW: For what reason does this feature use the term Form. Did I miss a way to define types e.g.?

@Lupp,

I miss a lot myself. Don’t use myself but have answered a question or two in past. It has problems if too many columns are involved. Types? - nothing on this and little on anything else. As for the term Form, I am still not certain why it is used in two different ways in Base. Seems if it concerns data and you don’t know what else to call it, just use Form :slight_smile:

Hi, @iwannaapple, an example follows:

image description

Set the macro to the first cell in your table.

Test file


ATTENTION: If you would like to give more details to your question, use edit in question or add a comment below. Thank you.

If the answer met your need, please click on the ball Descrição da imagem to the left of the answer, to finish the question.