How to Create OpenOffice.org Database Macros

Automating Base ODB Files by Using OpeOffice Basic

© Mark Alexander Bain

Jun 19, 2009
How to Create OpenOffice.org Database Macros, Mark Alexander Bain
Release 3.1 of OpenOffice.org gives programmers a new facility - the ability to save macros as part of a database file.

Unfortunately the release of OpenOffice.org 3.1 means that any database developers now have much more work to do and will be having even less of a social life. That's because they're going to be busy installing this new version on both their own and their clients' computers. Why is that? Because OpenOffice.org version 3.1 has added macros to database documents.

What is a Macro?

Many users of OpenOffice.org Writer and Calc will already be well versed in the creation and use of macros. A macro is, quite simply, a section of code stored and run from the application. This code is written in OpenOffice.org Basic which is very similar to (but not the same as) languages such as Visual Basic. And, up until version 3.1, that has not been available in OpenOffice.org Base.

One of the key differences between OpenOffice.org Basic and other forms of Basic is its reliance on the OpenOffice.org UNOs (Universal Network Objects). UNOs:

  • are the objects that make up the OpenOffice.org applications - for example Calc, Writer and Base
  • are platform independent objects - so that OpenOffice.Basic works equally well on a Linux computer or a Windows computer
  • are language independent objects – and can, therefore, be used in applications written in OpenOffice.org Basic, Visual Basic, Java, Python or C# (to name but a few)

The end result is, of course, that a very powerful macro can be build with the minimum of knowledge about the actual workings of an OpenOffice.org database.

Creating a New OpenOffice.org Database Macro

The process of creating a new OpenOffice.org database macro is quite simple in version 3.1:

  1. Open an existing OpenOffice.org database or create a new one
  2. Click on:
    • Tools
    • Macros
    • Organize Macros
    • OpenOffice.org Macros
  3. A dialog box will be displayed at this point. Select the database's .odb file and click on “New” (as shown in figure 1 at the bottom of this article)
  4. The application will request for a name for the new module (the storage area for macros). It's always better to use a more meaningful name than the default “Module1”

At the end of this short process the OpenOffice.org Basic IDE (Integrated Design Environment) will be displayed, complete with a blank macro (as shown in figure 2).

Developing a Complete Database Application

The ability of saving macros as part of an OpenOffice.org database means that the developer can create a complete database application. The macros can be used to:

  • process the contents of the database
  • process user input and outputs
  • open forms and dialogs when the database is opened
  • automatically register the database when it is placed on a new user's computer

Now OpenOffice.org Base is, at last, a viable alternative to Microsoft Access. Rather than justusing Base as a prototyping tool, the database developer can consider building a professional, self contained, database application.


The copyright of the article How to Create OpenOffice.org Database Macros in Database Programming is owned by Mark Alexander Bain. Permission to republish How to Create OpenOffice.org Database Macros in print or online must be granted by the author in writing.


How to Create OpenOffice.org Database Macros, Mark Alexander Bain
Figure 1: Creating an OpenOffice Database Module, Mark Alexander Bain
Figure 2: The OpenOffice Basic IDE, Mark Alexander Bain
   


Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo