Solving initialization event in unloaded library?

How do I make sure that the My Macros & Dialogs libraries are initialized before my Document’s WhenLoading event fires?

Here’s the deal: For Form initialization I use the WhenLoading event. It calls a sub in My Macros & Dialogs to help do it’s work. At first, it can’t find the sub in My Macros & Dialogs; then later it can find it, without changing anything at all. 8-|

This is the error message: image description Click OK, and almost magically, this error goes away until I re-start LO. When I say it starts working properly, I mean if I enter and exit design mode to re-fire the WhenLoading event, I don’t see this error on successive firings of the event. I only see it when I first start up LO.

It seems to fail only if the event handler calls a sub in a shared library as part of it’s work. In this case I’m calling this helper subroutine: My Macros & Dialogs, "Lookup.Lookup.WhenLoading_"

image description

My event handler works consistently if located entirely in the Document’s Standard.Module1:
image description

My event handler is this

image description

Finally, there is this little temporarily S icon in the Object Catalog marking the subroutine library I am trying to call. If I click on the library to view it’s modules the “S” goes away.

image description

When LO starts up it loads the Standard Library in My macros & Dialogs. When a document is opened it loads the Standard library in the document if there is one. The code in these Librarys is then available. Any other Library needs to be explicitly loaded before use using -


You found that there were no problems when you put the code in the Document Standard Library. I seem to remember you were talking about this in another post relating to the use of MRI and loading this Library. I dont understand why it works when you try it a second time.

If you start LO, without opening a document, and look at the Object Catalog you will see the Standard Library has a diamond icon. The icon that looks like a folder with an “S” which you see for your Lookup Library indicated it is not loaded. When you click on it the Library is loded and the icon changes to a diamond.

Right on! GlobalScope.BasicLibraries.LoadLibrary("Lookup") as the first thing in Sub AfterRecordChange(oEvent As Object) ... fixed this. (Interestingly, AfterRecordChange fires before the first WhenLoading.) Thank you.

[UPDATE While this hack below works, the solution by PeterWT here is a much better solution I think.]

:-/ I think I just came up with a solution to this. :slight_smile: Explaining this to you helped me.

So I don’t know if this is the best way, but I created this dummy sub in the module that wasn’t loading:

Sub Dummy(oEvent As Object)
End Sub

And then hooked it up to the Start Application event, as follows:

Tools, Customize, Events tab, then
Click Start Application, Macro..., and then select My Macros, Lookup, Lookup, Dummy, OK
and then be sure to select: Save In: LibreOffice Start Application (important), and click OK.