Base Form macro basic command "how to open Form on new record state ?"

I have two forms, one call the other from a button linked with a macro command.
I’m trying to just move state of my opened form at “new record” (same state if i click Form navigation bar button arrow “new record”). Then eventualy, set value of a field (listbox for a foreign key field).
But the method named “moveToInsertRow” show an error SQL message.

Here is my macro code:

Option Explicit

Type ProduitsTable
	ID         As Integer
	Model      As String
	Categorie  As Integer
	Nom        As String
	Desciption As String
	Marque     As String
end Type

Sub OpenProduitWithCategory(oEvent)
  Dim callerForm, callerMainForm
  Dim produitFormulaire, produitMainForm, produitCategory, produitDoc, produitCtrl
  Dim Produits As ProduitsTable
  callerForm = oEvent.source.model.Parent
  callerMainForm = callerForm.parent
  Produits.Categorie = callerMainForm.GetByName("Catégorie sélection").getcurrentValue(1)
  produitFormulaire = ThisDatabaseDocument.FormDocuments.getByName("Produit")
  produitFormulaire.open
  produitDoc      = produitFormulaire.GetComponent
  produitCtrl     = produitDoc.getCurrentController
  produitMainForm = produitDoc.drawpage.forms.getByName("MainForm")
  produitCategory = produitMainForm.getByName("Catégorie sélection")
  produitMainForm.moveToInsertRow
End Sub

and the error provide by libreoffice (is also cut because i can not change dimension of the dialogbox for read full message, libreoffice lock the GUI dimension box ability) is:

error exception happen
type: com.sun.star.sdbc.SQLException
message: error function sequence…
(nothing more, i don’t know if this normal to have this so short error information or if it is because libreoffice on linux doesn’t let user change dimension of the dialog message box who show messages… but i have to do with that)

and here is my full odb file about that: https://filebin.ca/3e63o6PtBjqw/Computer_elements.odb

What i not understand ? (hope it is not a bug)
I try to find and use XRay tool for see what kind of methods exists… read volonters codes and tutos, fight two days for slow evolution. It means to be very complicate to do currents usual things.

Hello,

Your sample and question don’t seem to match. You state you have two forms (there are four in the sample) with one called by a button linked by a macro command. I find many buttons and a macro but none of the buttons are linked to the macro. This makes it difficult to understand what is happening. Also it is unclear as to exactly what you are looking to accomplish. You state to open form at new record but also set a value in list box but never talk about this value.

Even with that, I believe the following should help you.

This first link (click here) contains a sample. It calls one form from another form and opens the second form at the record which was in the first form. Further explanation of this process can be seen on this post - click here. Now if you want to open the second form at a new record, the sample in the first mentioned link is modified to do that in this post - click here. This code should be what you are looking for.

Setting a form to be positioned at a new record is simply:

oForm = ThisComponent.Drawpage.Forms.getByName("MainForm")
oForm.moveToInsertRow

If you are opening a form from another form and you want the new form to point to a new record, you will need two macros. The button on the first form should perform the call to open the second form and close this first form if wanted. The second form should then have a macro attached to the Open Document event which will set the record at a new record. All this is in the links provided above.