Base : How to control insert into a form in order to generat my own keys by macro ?

Hi,

I would like to control key generation by macro when inserting a new row into a form with Base. But the risk is to execute twice insert action : the first with my handling insert event (I want to manage the mapping and use my own generated keys) and the second by the form base code automatically ....

So, if I set the property {AllowInserts = false}, do the Form stop to handling the insert but continue to fired /"Before Record Action"/ and /"After Record Action"/ events ? I think no, because the form could will not display the new line to insert ...

So I need to stop the handlind to the Form after my own into events. But I understand /"After Record action"/ event handling use a /"Sub"/ action not a /"function"/, so I can't return false after my handling ...

So how to do ?

Thank you for your help...
Patrick
/

Hi Patrick,

So, if I set the property {AllowInserts = false}, do the Form stop to
handling the insert but continue to fired /"Before Record Action"/ and
/"After Record Action"/ events ? I think no, because the form could will
not display the new line to insert ...

You will need "Before Record Action". After the action the data will be
inserted.
You will also need AllowInserts = true. Without this you couldn't get
the cursor in a new row.
The macro should do something like this:

SUB InsertStop(oEvent AS OBJECT)
DIM oFormFeature AS OBJECT
DIM oFormOperations AS OBJECT
oFormFeature = com.sun.star.form.runtime.FormFeature
IF oEvent.Source.ImplementationName =
"org.openoffice.comp.svx.FormController" THEN
oFormOperations = oEvent.Source.FormOperations
YourInsertFunction()
oFormOperations.execute(oFormFeature.UndoRecordChanges)
REM oFormOperations.execute(oFormFeature.MoveToLast)
END SUB

The YourInsertFunction() does exist, or do I understand your mail the
wrong way?

Regards

Robert

Thank you very much Robert :slight_smile:

But it looks strange to call "UndoRecordChanges" form operation after my own "YourInsertFunction", it look like this call undo my own insert ...
then, undo the operation of the form is not really no operation of the form ...

Could you please tell me more about the form operations ? In the book Robert Benitez - Database Programming OpenOffice.org Base & Basic - Cecilia Benitez, 2008 I find out nothing about all this ...

Do you think an other solution would be to lock the form controller or cancel the event, into "Before Record Action" handling ? I could find /"myDocument.lockControllers"/ function but it will stop only the interface refresh ...

Patrick

Hi Patrick,

But it looks strange to call "UndoRecordChanges" form operation after my
own "YourInsertFunction", it look like this call undo my own insert ...
then, undo the operation of the form is not really no operation of the
form ...

This should stop the prozess. I have had a look here
https://api.libreoffice.org/docs/idl/ref/FormFeature_8idl.html
and found nothing else to stop the process.

Could be
oFormOperations.execute(oFormFeature.ReloadForm)
oFormOperations.execute(oFormFeature.MoveToLast)

will switch to the new input you have inserted by yourself.

Could you please tell me more about the form operations ? In the book
Robert Benitez - Database Programming OpenOffice.org Base & Basic -
Cecilia Benitez, 2008 I find out nothing about all this ...

Most of the code I am using I have learned of the German book about
BASIC from Thomas Krumbein and also in message boards.

I have written down all this in the German Base-Handbuch, but it isn't
translated yet in English. The German version you could find here:
https://de.libreoffice.org/get-help/documentation/

Regards

Robert

Hi,

I would like to control key generation by macro when inserting a new row
into a form with Base. But the risk is to execute twice insert action :
the first with my handling insert event (I want to manage the mapping
and use my own generated keys) and the second by the form base code
automatically ....

There are two paths to this:
One: setup a inert trigger in the database engine to do this.
Details on creating triggers vary depending on the engine you are using.
This works if the data you use to assemble your key is already in the
database (fields in other tables for instance).
OR
Two: handle it with the client application (Base) which seems to be the
advice you are getting so far.

The decision as to which way to go depends on how you want to use it, doing
it with a triggere means that any form, or table grid, attached to the
table will pick up the function but you if you want to read values from
form controls to construct your key the client side work work best.

Best wishes,

Drew

So, if I set the property {AllowInserts = false}, do the Form stop to
handling the insert but continue to fired /"Before Record Action"/ and
/"After Record Action"/ events ? I think no, because the form could will

not display the new line to insert ...

Ok, that question gets into