Ask Your Question
0

How to autostart a Form by default at ODB opening ?

asked 2016-09-07 20:01:14 +0200

kirsch gravatar image

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 flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2016-09-07 21:30:03 +0200

Ratslinger gravatar image

updated 2016-09-07 21:32:24 +0200

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.

edit flag offensive delete link more

Comments

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 gravatar imagemav192 ( 2019-01-31 23:06:58 +0200 )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.

Ratslinger gravatar imageRatslinger ( 2019-01-31 23:22:40 +0200 )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.

mav192 gravatar imagemav192 ( 2019-01-31 23:26:01 +0200 )edit
0

answered 2018-02-28 18:44:48 +0200

dominic.joannou gravatar image

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.

edit flag offensive delete link more

Comments

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

Ratslinger gravatar imageRatslinger ( 2018-02-28 19:12:36 +0200 )edit
Login/Signup to Answer

Question Tools

2 followers

Stats

Asked: 2016-09-07 20:01:14 +0200

Seen: 2,109 times

Last updated: Feb 28 '18