How to autostart a Form by default at ODB opening ?

I would like to have the “FormNew” to open automaticly when Opening the data base "LibO_RKM_start_FormNew.odb. Is there a macro to do that on the attached base example ?

This is basically the same routine presented in this past post:

SUB OpeningForm
  Dim ObjTypeWhat
  Dim ObjName As String
  ObjName = "FormNew"
  ObjTypeWhat = com.sun.star.sdb.application.DatabaseObject.FORM
  If ThisDatabaseDocument.FormDocuments.hasbyname(ObjName) Then 'Check the form exists'
     ThisDataBaseDocument.CurrentController.Connect() 'If the form exists connect to the database'
     ThisDatabaseDocument.CurrentController.loadComponent(ObjTypeWhat, ObjName, FALSE) 'Open the form'
  Else
      MsgBox "Error! Wrong form name used. " & ObjName
  End if
End Sub

From menu Tools->Customize attach the macro to Open Document Event of .odb then Save, close the .odb and re-open. Form should start automatically.

2 Likes

Hi!

I am using LibreOffice 6.0.7.3 and when I try to run this macro the error message pops up:

“Basic runtime error.
Object variable not set.”

It refers to the 6th line: If ThisDatabaseDocument.FormDocuments.hasbyname(ObjName).

However, when I deleted it the same error occurred, but it referred to the 7th line and then after doing the same, to the 8th line, therefore something is apparently wrong with those 3 lines. If someone knew what and could help, I would be grateful!

@mav192 Have you changed the following line:

ObjName = "FormNew"

The answer here is specific to a question and the form named FormNew. This is also a continuation of a related post (see link in answer) which shows this field to be filled in from elsewhere. If you change this to the name of your form it will work but please look at the linked answer also.

Yes, of course.

I have actually resolved this issue just now. I am simply stupid, since I have saved the Macro not under my database, but outside of it if you know what I mean. Thanks a lot anyway.

Using this macro / solution it does indeed open the form. It opens however in a black screen on which I can only see the toolbars. Resizing the form to full screen it will give me the original document and colors back… How can I solve this?
I use LibreOffice 7.1.4.2 (x64)

@MembrojBart,

Have not seen or heard of this problem with this code. Do not know what OS you have, but if Win 10, try removing use of Skia. From menu Tools->Options. Then under LibreOffice->View will be in right hand pane on right side.

Dear Ratslinger,

Thank you for you advice.

Under Tools-.Customize I cannot find “Open Document”. There is “Open Database Object”. I am not sure how it would attache.

@dominic.joannou

First, please use comment for this type of response. Answers should be used to respond to original question.

You seem to be looking under the incorrect Tab in Tools->Customize. You will find it under the Event tab.

1 Like