More than one table in a form?

Creating and using forms
Post Reply
mn1247
Posts: 10
Joined: Sat Apr 19, 2008 2:43 pm

More than one table in a form?

Post by mn1247 »

Okay... dumb newbie-type question...

I'm using a Writer document as a database front-end. Here's my question: in a Form, do all of the form elements have to reference the same table? Or, can there be more than one table?

If the latter is possible, how is it achieved? The form properties dialog seems to only allow one table to be specified.

Thanks in advance for any help.

Eric
User avatar
voobase
Volunteer
Posts: 97
Joined: Tue Jan 15, 2008 3:07 pm
Location: Australia

Re: More than one table in a form?

Post by voobase »

Hi Eric,

In each "writer doc" form you can have multiple forms that reference different data tables or queries. You can have multiple mainforms and on each of these you can attach multiple subforms. The idea of a subform is that you then link/join a field from your mainform to one in your subform. This is usually the Primary Key field from the mainform's data table to a field in the subform's data table which will be then thought of as being a Foreign Key field. This way you can have a 1 : n type form setup, where multiple subform records can exist for each mainform record. You could also have multiple link/joins which can have several uses. Following on from this it is then possible to have subsubforms linked/joined to each subform. To see what is occuring here and to create new forms, you will need to learn how to use the "form navigator", which is a button on the "form design" toolbar. You must be in "design mode" to be able to access these buttons.

To see this for yourself create two tables in design view (I don't like the form wizard). Here is some brief instructions...

1/ Create a field such as "surnames" and leave the data type as varchar.

2/ Press save and it will prompt you to allow it to create a primary key. Choose Yes.

3/ Straight away click on the "ID" field and down the bottom change "autovalue" to yes.

4/ Save and exit.

5/ Now create another table but this time call the field something like "books_read". Also create an additional field called "Surnames_FK"

6/ Launch the "Form's Wizard". Follow it through adding your second form as a subform. When asked join table 1's "ID" field to table 2's "Surname_FK".

7/ Close the form down after it has launched and this time right click on the form (in the GUI) and select "edit". This is launching the form in "design view".

8/ Find the "form design" toolbar and there is a button on that which toggles design mode on and off. There is also a button on there which is the "form navigator" that I talked about earlier.

9/ The "form navigator" gives you a "tree" like view of your form. Right click where it says "forms" to add another mainform. Right click on a mainform and choose form to add a subform to it. Right click on any form of control in the tree and choose "properties" to examin the properties. Look for the data tab and in here you can change the datasource for the form or data field for the control. In the subform data properties you can set up the link/join between subform and mainform.

10/ Other good things to know.... There is a button on the "form controls" toolbar called "wizard". Have this pressed in and when you add a listbox or combobox to your form a wizard is launched. There is also a handy "form navigator" control in the "more controls" toolbar. You can draw this on your form to give yourself a navigation control specific to each mainform or subform.

I hope this gets you started...
Cheers

Voo
OOo 2.3.X on MS Windows Vista
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: More than one table in a form?

Post by Villeroy »

Normally you link your form to a query rather than table. A query can comprise many fields across many tables. Additionally you can create subforms, related to main forms and more than one main form in a single office document.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply