Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hello,

You can create forms from a Writer document in Base using a small macro.

This is published in the document AndrewBase by Andrew Pitonyak found here -> Database access using OpenOffice.org.

Section 2.3.2 deals with creating a form using a macro. While this entails controls as well as the basic form, the end of the routine contains code to convert the Writer document to the Base form.

As mentioned by @Alex Thurgood you can create the form using the GUI (or even directly with Writer). Then Save as .odt as your template.

Here is the macro:

Option Explicit

Sub Main
    dim oProps(2) as new com.sun.star.beans.PropertyValue
    dim oDocDef, oFormDocs 
    dim sFormName, sVar as string
    sFormName = InputBox("Please enter name for form:", "Form from Writer Document")
    oFormDocs = thiscomponent.FormDocuments
    If oFormDocs.hasByName(sFormName) Then
        sVar = MsgBox(Chr(10) & "Form " & sFormName & " already exists!" & Chr(10) & Chr(10) & "Yes to overwrite; No to Exit", 132, "Form Already Exists!")
        If sVar = 7 Then Exit Sub
        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 = convertToUrl("/home/YOUR_DIRECTORY/MyBaseTemplate.odt")
Rem Windows:
    'oProps(2).Value = convertToUrl("C:\YOUR_DIRECTORY\MyBaseTemplate.odt")
    oDocDef = oFormDocs.createInstanceWithArguments("com.sun.star.sdb.DocumentDefinition", oProps())
    oFormDocs.insertbyName(sFormName, oDocDef)
    Print "Added " & sFormName & " to the database"
End Sub

Have slightly modified the original code to allow input of the form name you want and an escape if the form name already exists. You only need to change the line with oProps(2).Value = convertToUrl("LOCATION/NAME") to reflect your template.

The macro should be saved in My Macros & Dialogs in a module under Standard. Forms can then be created using this by executing the macro from your main Base screen menu Tools->Macros->Run Macro....