Button click event

Hi.
Thinking about Abstimmungsschaltfläche mit Aktion belegen
So button click has neither Properties nor Methods ?
:thinking:

Option Explicit
Sub SetOption(Evt As Object)
	GlobalScope.BasicLibraries.loadLibrary("MRILib")
	Dim Doc As Object, SForm As Object, Form As Object, RBJ As Object
	On Error GoTo Erro
	MRI Evt

image
Form

 
TIA!

what about the Property Source ?!

btw. why do you only provide a Screenshot with the »Property« to be »Visible« for other people?

The object “Event” is not an object “Button”. The Button object is available through the Source property (as the source of the EVENT).

My shameful mistake: simply didn’t notice it!
Sorry :flushed:

My bad: sorry!
Goal was to get rid of

  • Doc (ThisComponent);
  • .ActiveSheet;
  • .DrawPage;

in the first routine. And :ok::

Form = Evt.Source.Model.Parent
RBJ = Form.getByName("rbJ") ' variable for the Ja control
StoreChoice(RBJ.State)
Exit Sub

Apologies again!

From any form control’s event, you get the sheet like this:

oModel = ev.Source.getModel()
oForm = oModel.getParent()
oForms = oForm.getParent()
oDoc = oForms.getParent()
oSheet = oDoc.CurrentController.getActiveSheet()

This works with a bunch of single controls on a flat form. It fails if your event source is a column in a table control or if your event source is part of a subform.

What you are trying to do is difficult. Hundreds of Calc users have tried this before without getting close to the functionality of a database form.

But it did work…
Question is: simply didn’t notice the Property Source in the MRI window.
Can’t express how shameful I am.

About this: how to get a “real” Form, not just controls spread out into or over the cells?

oForms = oForm.getParent()

@Gbp:
Form Properties… :thinking:
 

No control without form. Form controls are attached to some dummy form which serves as control container without being bound to any database. Click the “Form Navigator” button on the “Form Design” toolbar and see.

This is my preliminary solution intended to be used with any pair of named range and database range. The named range is one row collecting the values for a new record to be inserted into the database range.
The submission macro performs a row insertion with full copy and paste and converts to values any formulas within the inserted database range cells.
Supernumerous formulas behind the database range remain untouched (e.g. lookup formulas).
Poor_Mans_Input_Form.ods (35.6 KB)

:+1:

Form = Evt.Source.Model.Parent ' variable for the dummy Form

 
PMIF
This is like “my” Form. But I would like to get a “real” Form: controls inside a frame, not spread out over or anchored to cells.
And as you can see, I’m not well acquainted with Spreadsheets.
This exercise of mine was motivated by Abstimmungsschaltfläche mit Aktion belegen’s question. Of course without the Tablet mit dem Finger requirement.
It persists
Timestamp | Choice
in the Records sheet.
Untitled 1.ods (14.7 KB)

Basic example of a spreadsheet form.

Formulario para planilha.ods (27,0,KB)

Your macro does roughly the same as mine, but:
– appending new data below the sheet’s used area, which may be the area below the list or may be not.
– without reference expansion. You need to take care of references in formulas and charts and everywhere.
– does not handle calculated columns.
– works with one form per document.

Yes: this is a “real” Form I’m talking about!
But don’t know how to build for the exercise.

Of course. But I did it thinking about Datum des Tippens und der Zähler sollen hochzählen Spalte Ja (Anzahl) + Spalte Nein (Anzahl).
So, persist
Timestamp | Choice: 0 (Nein) - 1 (Ja)

As I said: Basic example.

Post a sample file; it makes it much easier to suggest something more productive.

Well, this should be done dynamically by means of ordinary spreadsheet formulas.
Without updating any references, you could also write your data to some text file. This is way easier without all the pitfalls of a spreadsheet.

f = "/tmp/test.csv"
ts = format(Now(), "yyyy-mm-dd hh:mm:ss")
v = ThisComponent.Sheets(0).getCellByPosition(0,0).getString()' Yes/No value
i = Freefile
Open f For Append As #i
Print #i, Join(Array(ts, v), ";")
Close #i