# 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 ?

edit retag close merge delete

Sort by » oldest newest most voted

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.

more

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!

( 2019-01-31 23:06:58 +0100 )edit

@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.

( 2019-01-31 23:22:40 +0100 )edit

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.

( 2019-01-31 23:26:01 +0100 )edit

Dear Ratslinger,

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

more

@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.

( 2018-02-28 19:12:36 +0100 )edit