In the previous blog about "hidden secrets" inside the OpenOffice.org software you've learned how easy it is to create push buttons. In the blog following this one, you will see how to add controls to your documents that display the contents of database fields.
Here and now we could need a database that is more than just a basic example. For users of OpenOffice.org, nice and useful database templates are already installed. You just rub the menu to summon a wizard that is waiting for you for eons to unveil the next hidden secret.
To create a new DVD collection database
-
Choose File - New - Database.
You see the Database Wizard.
-
Click Next>> to continue to page 2 of the Database Wizard. -
Check "Create tables using the table wizard". Then click Finish. -
Enter a name for the new OpenOffice.org Base file, for example mydvds, and save the file.
You see the opened Base file, but wait, something happens automatically:
-
The Table Wizard opens.
-
Click the Personal radio button. Select DVD-Collection from the list box. Then click the >> button to move all available fields to the right. This instructs the wizard to add all available fields to the new table. -
Click Next> twice to continue to the "Set primary key" page.
-
Check the "Auto value" box. Then click Next>.In OpenOffice.org Base, every table needs a primary key. A primary key is a field with unique contents for every data record. "Auto value" inserts a unique value into that field for every new record.
-
On the final page of the Table Wizard, click "Create a form based on this table".
-
Click Finish. Next you see the Form Wizard.
-
Click the >> button to move all available fields to the right. Then select the ID field and click the < button to move that field back to the left.
The ID field is the automatically filled primary key field. This field must be present in the table, but it needs not be shown in a form.
-
Click Next> twice to advance to the "Arrange controls" page.
-
Click the second of the four big icons under "Arrangement of the main form".
The reason is that I personally prefer this choice from the four arrangements.
-
The remaining pages of the Form Wizard can be used for some fine-tuning, if you want so. I'm sorry for the choice of colors on the "Apply styles" page. Click Finish any time to create the form.
The ready-made DVD-Collection form looks like this now:
You see two columns with all selected fields in alphabetical order of their labels.
The form is saved automatically to the new Base file mydvds.
The form shows "(read-only)" in the title bar. That is a sign that you can enter the data records now. If you rather want to edit the form layout, you can do so from the Base file that is still open in the background.
- Right-click the DVD-Collection entry and choose Edit if you want to edit the form layout.
- You can change the form properties, for example, the size and position of the fields, or the background color.
- In the Base file, double-click the name of your form, or click Open, to open the form in data input mode.
- Enter some data records. The new or changed data is stored automatically once you go to another data record.
Now we have a database ready for the next blog. In the next blog we will learn how to create form controls inside a Writer document, and this time the form controls will be connected to some database fields. That's the plan, don't know yet if that's possible at all - stay tuned to this blog.
