OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

creating a form with a macro

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
lm
General User
General User


Joined: 06 Sep 2006
Posts: 14
Location: Ontario, Canada

PostPosted: Sat Oct 14, 2006 3:37 am    Post subject: creating a form with a macro Reply with quote

Hi,

First of all, many thanks to Andrew Pitonyak for your wonderful AndrewMacro and AndrewBase documents.

That said, I'm having trouble adding a macro created form to my database. I have no problem creating the form, but when I try to store it in my Base document, I get the following error message.

BASIC runtime error.
An exception occurred
Type: com.sun.star.lang.IllegalArgumentException
Message: Wrong connection mode is provided

( I marked the line that's causing the error in the following code with asterisks.) The code is copied from the AndrewBase document, but note the changes I made, I got rid of the arguments to the function, I don't want the form linked to a table, and I hardcoded the URL.

If you need to see more of my code, just ask!

Thanks a lot!
lm

Sub AddReportForm
Dim oDoc 'Newly created Form document
Dim oDrawPage 'Draw page for the form document.
Dim s$ 'Generic temporary string variable.
Dim oDBDoc 'The Base database document.
Dim sDBName$ 'Name portion from sDBURL.
Dim sFormURL$ 'URL where the temporary form is stored.
Dim oFormDocs 'Form documents in the Base document.
Dim sFormName$ 'Form name as stored in the Baes form documents.
Dim oDocDef 'Document defition of the form stored in Base.

Dim NoArgs() As new com.sun.star.beans.PropertyValue
Dim oProps(2) as new com.sun.star.beans.PropertyValue

sDBURL$ = "file://home/lorne/database/AI Manufacturing.odb"
sFormURL ="file://home/lorne/database/AI report.odt"

REM Create a new document for the form.
s$ = "private:factory/swriter"
oDoc = StarDesktop.LoadComponentFromURL(s$, "_default", 0, NoArgs())

REM The form will in edit mode, rather than design mode, by default.
oDoc.ApplyFormDesignMode = False

Dim oViewSettings
oViewSettings = oDoc.CurrentController.ViewSettings
oViewSettings.ShowTableBoundaries = False
oViewSettings.ShowOnlineLayout = True

REM Get the document's draw page and force the top level form to
REM exist and be named "Standard".
oDrawPage = oDoc.DrawPage
If oDrawPage.Forms.Count = 0 Then
s$ = "com.sun.star.form.component.Form"
oDBForm = oDoc.CreateInstance(s$)
oDrawpage.Forms.InsertByIndex (0, oDBForm)
Else
oDBForm = oDrawPage.Forms.GetByIndex(0)
End If
oDBForm.Name = "Standard"

REM Cause the form to use the table as a datasource.
oDBForm.DataSourceName = sDBURL
oDBForm.Command = sTableName
oDBForm.CommandType = com.sun.star.sdb.CommandType.TABLE

REM Service names for controls.
Dim sLabel$ : sLabel = "com.sun.star.form.component.FixedText"
Dim oControl 'A control to insert into the form.
Dim oShape 'Control's shape in the draw page.
Dim oLControl 'Label control.
Dim oLShape 'Label control's shape in the draw page.

REM Anchor the controls to paragraphs.
Dim lAnchor As Long
lAnchor = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH

REM Insert the ID label
oLControl = oDoc.CreateInstance(sLabel$)
oLControl.Label = "ID"
oLControl.Name = "lblID"

oLShape = oDoc.CreateInstance("com.sun.star.drawing.ControlShape")
oLShape.Size = createSize(1222, 443)
oLShape.Position = createPoint(1000, 1104)
oLShape.AnchorType = lAnchor
oLShape.control = oLControl
REM Do not add the label control yet!

REM Insert the ID formatted text field
s$ = "com.sun.star.form.component.FormattedField"
oControl = oDoc.CreateInstance(s$)
oControl.LabelControl = oLControl
oControl.BackgroundColor = 14540253
oControl.Border = 1
oControl.DataField = "ID"
oControl.EffectiveMax = 2147483647
oControl.EffectiveMin = -2147483648
oControl.EnforceFormat = True
oControl.HideInactiveSelection = True
oControl.Name = "fmtID"
oControl.TreatAsNumber = True

oShape = oDoc.CreateInstance("com.sun.star.drawing.ControlShape")
oShape.Size = createSize(2150, 651)
oShape.Position = createPoint(2522, 1000)
oShape.AnchorType = lAnchor
oShape.control = oControl
oDrawpage.Add(oLShape)
oDrawpage.Add(oShape)

REM Insert the Name label
oLControl = oDoc.CreateInstance(sLabel)
oLControl.Label = "NAME"
oLControl.Name = "lblName"

oLShape = oDoc.CreateInstance("com.sun.star.drawing.ControlShape")
oLShape.Size = createSize(1222, 443)
oLShape.Position = createPoint(1000, 1954)
oLShape.AnchorType = lAnchor
oLShape.control = oLControl

REM Insert the Name text field
s$ = "com.sun.star.form.component.TextField"
oControl = oDoc.CreateInstance(s$)
oControl.BackgroundColor = 14540253
oControl.Border = 1
oControl.DataField = "NAME"
oControl.LabelControl = oLControl
oControl.Name = "txtNAME"

oShape = oDoc.CreateInstance("com.sun.star.drawing.ControlShape")
oShape.Size = createSize(8026, 651)
oShape.Position = createPoint(2522, 1850)
oShape.AnchorType = lAnchor
oShape.control = oControl
oDrawpage.Add(oLShape)
oDrawpage.Add(oShape)

REM Add the Image control
s$ = "com.sun.star.form.component.DatabaseImageControl"
oControl = oDoc.CreateInstance(s$)
oControl.BackgroundColor = 14540253
oControl.Border = 1
oControl.DataField = "DATA"
oControl.Name = "imgDATA"

oShape = oDoc.CreateInstance("com.sun.star.drawing.ControlShape")
oShape.Size = createSize(10504, 7835)
oShape.Position = createPoint(2522, 3332)
oShape.AnchorType = lAnchor
oShape.control = oControl
oDrawpage.Add(oShape)

REM At this point, we have a Form, which is a Write document.
REM Store the stand alone form to disk. This form is usable as is.

REM Use some methods from the Tools library.
If NOT GlobalScope.BasicLibraries.isLibraryLoaded("Tools") Then
GlobalScope.BasicLibraries.LoadLibrary("Tools")
End If

REM Store the form to disk and then close the document.
oDoc.StoreAsUrl(sFormUrl, NoArgs())
oDoc.close(True)

REM Now, convert the form on disk to a document defition and
REM store it in a Base document.

oDBDoc = FindComponentWithURL(oDBSource.DataBaseDocument.URL, True)
'oDBDoc = StarDeskTop.loadcomponentfromURL(oDBSource.DataBaseDocument.URL,"_Hidden", 63, Array())
oFormDocs = oDBDoc.getFormDocuments()
If oFormDocs.hasByName(sFormName) Then
Print "Removing " & sFormName & " from the database"
oFormDocs.removeByName(sFormName)
End If

oProps(0).Name = "Name"
oProps(0).Value = sFormName
oProps(1).Name = "Parent"
oProps(1).Value = oFormDocs()
oProps(2).Name = "URL"
oProps(2).Value = sFormUrl

s$ = "com.sun.star.sdb.DocumentDefinition"

'xray oFormDocs
oDocDef = oFormDocs.createInstanceWithArguments(s$, oProps())


*********************************************************************************
oFormDocs.insertbyName(sFormName, oDocDef) 'line causing error
*********************************************************************************

Print "Added " & sFormName & " to the database"
End Sub
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group