Code: Select all
ThisDatabaseDocument.FormDocuments.getbyname("FormName").open
Code: Select all
ThisDatabaseDocument.reportDocuments.getbyname("ReportName").open
This all works fine.
However, if I load MainMenu automatically when the database opens, by calling the following macro from the database's Open Document event
Code: Select all
Sub AutoExec
On Error Goto HandleError
Dim FormDocs, DBDoc, DataSource, Conn, FormDoc As Object
Dim Args(1) As New com.sun.star.beans.PropertyValue
Dim FormName, UserName, Password As String
UserName="" : Password=""
DBDoc=ThisComponent
DataSource=DBDoc.DataSource
Conn=DataSource.getConnection(UserName,Password)
FormName="MainMenu"
FormDocs=DBDoc.FormDocuments
Args(0).Name="ActiveConnection" : Args(0).Value=Conn
If FormDocs.hasByName(FormName) Then
FormDoc=FormDocs.loadComponentFromURL(FormName,"_self",0,Args() )
'FormDoc.CurrentController.Frame.ContainerWindow.setFocus()
FormDoc.CurrentController.Frame.ComponentWindow.setFocus()
Else
MsgBox "No form named: " & FormName
End If
HandleError:
If Err<>0 Then
MsgBox "An error occured while loading the form [ " & FormName & " ]"
Exit Sub
End If
End Sub
If I close MainMenu and reopen manually, then the report opens without an error. Can anyone explain what is going on here? And perhaps how to solve the problem.
Regards,
Nocton