Frank Schönheit - Sun Microsystems Germany wrote:

Hi Andrew,

'oFormDoc = oFormDef.execute(sOpenMode, nCmd, eEmpty) ' Variable NOT defined 'oFormDoc = oFormDef.execute(sOpenMode, nCmd, oNull) ' Object Variable NOT set 'oFormDoc = oFormDef.execute(sOpenMode, nCmd, NULL) ' Object Variable NOT set
 'oFormDef.releaseCommandIdentifier(nCmd)

In all three cases, the error message was not about the last parameter,
but about "sOpenMode". |execute| does not take a string, but a
com.sun.star.ucb.Command - sorry for the confusion, I blindly assumed it
were a string. This of course (unnecessarily) complicates the macro when
using |execute|.

To make things worse, our implementation currently also requires a
OpenCommandArgument2 to be present in the Command structure - either
directly in its |Argument| member, or, if |Argument| is an array of
property values, in one of the values in this array. This again is
unnecessary, but sadly complicates things even more.

The complete solution would look as follows:

Dim identifier as Long
identifier = oForm.createCommandIdentifier()

Dim UcbCommand as new com.sun.star.ucb.Command
UcbCommand.Name = "openDesign"
Dim Arguments as new com.sun.star.ucb.OpenCommandArgument2
Arguments.Mode = com.sun.star.ucb.OpenMode.DOCUMENT
UcbCommand.Argument = Arguments

Dim environment as Object

Dim component as Object
component = oForm.execute( UcbCommand, identifier, environment )

This, of course, makes me to completely withdraw my statement about
|execute| being easier to use than |loadComponentFromURL| :(
(though I think we will do something about it, at least we should not
required an OpenCommandArgument, but default it)

Ciao
Frank

If the command name is "open" rather than "openDesign", than an active connection is required, or the form will load but will not be able to access the database because it has no connection. At least I assume this is why I have the problem that I do with this method. Here is the code that I am actually using:

Function OpenFormInDB2(sDBURL$, sFormName$)
 Dim oDBDoc          'The database document that contains the form.
 Dim oFormDef        'com.sun.star.sdb.DocumentDefinition of the form.
 Dim oFormDocs       'The form documents container.
 Dim oFormDoc        'The actual form document.
 Dim oBaseContext    'Global database context service.
 Dim oDataBase       'Database obtained from the database context.
 Dim oCon            'Database connection.
 Dim oParms() As New com.sun.star.beans.PropertyValue


 REM Find the database document and open it if required.
 oDBDoc = FindComponentWithURL(sDBURL$, True)
 If IsNULL(oDBDoc) OR IsEmpty(oDBDoc) Then
   Print "The document was not found"
   Exit Function
 End If

 oFormDocs = oDBDoc.getFormDocuments()
 If NOT oFormDocs.hasByName(sFormName) Then
   Print "The database does not have a form named " & sFormName
   Exit Function
 End If

 oFormDef = oDBDoc.getFormDocuments().getByName(sFormName)
 oBaseContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
 oDataBase = oBaseContext.getByName(sDBURL)
 'oCon = oDataBase.getConnection("", "")
 AppendProperty(oParms(), "ActiveConnection", oCon)

 Dim identifier as Long
 identifier = oFormDef.createCommandIdentifier()

 Dim UcbCommand as new com.sun.star.ucb.Command
 UcbCommand.Name = "openDesign"  'Or "open" or "openForMail"
 Dim Arguments as new com.sun.star.ucb.OpenCommandArgument2
 Arguments.Mode = com.sun.star.ucb.OpenMode.DOCUMENT
 UcbCommand.Argument = Arguments

 Dim environment as Object
 oFormDoc = oFormDef.execute( UcbCommand, identifier, environment )
 OpenFormInDB2() = oFormDoc
End Function

****************************

Note that I am able to use the following:

Function OpenFormInDB1(sDBURL$, sFormName$)
 Dim oDBDoc          'The database document that contains the form.
 Dim oFormDef        'com.sun.star.sdb.DocumentDefinition of the form.
 Dim oFormDocs       'The form documents container.
 Dim oFormDoc        'The actual form document.
 Dim oCon            'Database connection.
 Dim oParms() As New com.sun.star.beans.PropertyValue
 Dim oBaseContext    'Global database context service.
 Dim oDataBase       'Database obtained from the database context.

 REM Find the database document and open it if required.
 oDBDoc = FindComponentWithURL(sDBURL$, True)
 If IsNULL(oDBDoc) OR IsEmpty(oDBDoc) Then
   Print "The document was not found"
   Exit Function
 End If

 oFormDocs = oDBDoc.getFormDocuments()
 If NOT oFormDocs.hasByName(sFormName) Then
   Print "The database does not have a form named " & sFormName
   Exit Function
 End If

 oFormDef = oDBDoc.getFormDocuments().getByName(sFormName)
 oBaseContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
 oDataBase = oBaseContext.getByName(sDBURL)
 oCon = oDataBase.getConnection("", "")
 REM OpenMode is rumored to support "open", "openDesign",
 REM and "openForMail"
 AppendProperty(oParms(), "OpenMode", "open")
 AppendProperty(oParms(), "ActiveConnection", oCon)
 oFormDoc = oFormDocs.loadComponentFromURL(sFormName, "", 0, oParms())
 OpenFormInDB1() =  oFormDoc
 REM If you close the connection, then the form loses its connection.
 REM The requirement of an Active connection should be removed,
REM hopefully in version 2.0.1. I am not convinced that this is really required.
 REM This really looks like a resource leak, but I have not checked.
 REM oCon.close()
End Function

In case you are wondering, I am adding more sections to my database document.... Trying to make the databae world more accessible...

--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.sxw
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info:  http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to