[Example] Relations reflected by list boxes in forms

Some examples to be used directly
Forum rules
No question in this forum please
For any question related to a topic, create a new thread in the relevant section.

[Example] Relations reflected by list boxes in forms

Postby Villeroy » Fri Apr 22, 2011 6:12 pm

Covering several of the most common misconceptions regarding relations in Base forms:

1) Base is a database program.
No, it isn't. HSQLDB is a relational database that can be wrapped into a Base document. You can connect your Base document to many other types of relational databases that are not wrapped into the document. Base is a tool set to work with databases in the context of this office suite.
Documentation of the built-in HSQLDB up to version 3.3 3.4: http://hsqldb.org/doc/guide/ch09.html (still the same in AOO 4.1)
Documentation of HSQLDB for future recent versions: http://hsqldb.org/doc which is the most recommended but not embedded database to be used with OpenOffice. But you are free to use MySQL, PostgreSQL, Oracle databases or whatever.

2) It is a good idea to build a nice looking form and attach a set of table data to the form.
Think the other way round. Base (sub-)forms and form controls are designed to reflect the relations of any relational database you connect at it. A relational database is a rigid structure of strictly typed fields. Base forms are a minimalistic set of tools to build fairly usable (rather than perfect) user interfaces for editable relations.
It is impossible to do anything useful with Base forms without having a perfectly normalized relational database.

3) The form wizard can help me to build a form to edit related data across tables
The wizard can reflect a single one-to-many relation with the one-side in main form and the many-side in the subform. Anything else requires a list box or a group of list boxes bundled in a table control. The form wizard never creates any list box. You've got to learn how to use the "Form Design" toolbar together with the controls on the "Form Controls" toolbar and its extension the "More Controls" toolbar.

4) Macro code can help me to build a form to edit related data across tables
This forum proves that this is an illusion unless you are an experienced programmer willing to spend a lot of time studying the API (application programming interface). Even then you won't get anywhere when you work against common rules of relational database design.

5) I need a combo box to select items from another table
No, you always need a list box to select items. A combo box is just an advanced text box with auto-complete. A combo box can be useful when you keep repetitive data in a field without implementing any relation. Sometimes simplicity is more important than integrity, but only sometimes.
Contrary to a combo box, a list box has two fields: A visible field (index #0) and a hidden field (bound field, mostly index #1). The visible field lets you pick another table's item by name, the bound field is the respective primary key of the selected item which gets written into the foreign key of the form's current record.
The recipe for a working list box is always the same:
Properties of your list box, tab "Data"

Variant #1:
Linked Field: XID [the foreign key where the other table's primary key gets stored]
Source type: SQL
Source: SELECT "Field A" AS "Visible", "Primary Key" AS "Bound" FROM "Your List" ORDER BY "Visible".
Bound Field: 1 [the other one would be 0]

Variant #2
Linked Field: XID [the foreign key where the other table's primary key gets stored]
Source type: Query
Source: MyListBox [name of the query SELECT "Field A" AS "Visible", "Primary Key" AS "Bound" FROM "Your List" ORDER BY "Visible"]
Bound Field: 1 [the other one would be 0]

For both variants, the visible field can include any calculated or concatenated string such as "Surname" || ', ' || "Forname" AS "FullName"

6) List boxes can filter record sets
A list or combo box selects a value into a field rather than selecting rows from tables. The form based filter provides a built-in but slightly clumsy method to filter by list box. The text fields in the attached database forms turn into list boxes when you turn on the form filter mode (3rd last button on the "Form Navigation" tool bar).
More on filtering: http://dl.dropbox.com/u/10552709/FilterExamples.zip

The ultimative Base tutorial: http://openoffice.org/projects/document ... 20tutorial
[Tutorial] Forms in OpenOffice.org Base helps to analyse and reproduce the forms in my attachment.
[Tutorial] Creating a form in Design view helps to analyse and reproduce the forms in my attachment.
[Example] Filter/Search with Forms (leveraging SubForms)
The attached Base document contains an embedded HSQLDB, a set of 4 tables constituting 2 relations one-to-many and many-to-many, 2 simple queries, 3 form documents with a README form and a simple grouped report from one of the queries.
In this context the report is not that important. It requires the report builder extension installed. Query "qReport" is a most simple demo how to merge data from all the tables into a virtual table. The report generates a printable Writer document from that record set. You may also create another report using the built-in simple report wizard or you may drag the query icon into some Writer or Calc document.
Attachments
relations2listboxes.odb
1:n and m:n in 4 tables, 3 formsforms
(65.23 KiB) Downloaded 4619 times
Last edited by Villeroy on Mon Jan 30, 2017 12:47 am, edited 3 times in total.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24807
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Example] Relations reflected by list boxes in forms

Postby mhatheoo » Fri Apr 22, 2011 9:40 pm

well villeroy, thanks for sending this nice introduction,
but I think this is really the very beginning, a little too few,
as the abilieties of HSQLDB are much ahead of this,
so I am not that much fond of reading you (personal) statements
about the restrictions within OOO-Base.

Martin
mh with ooo 3.3.0 + LO 3.3.2 on w2k
mhatheoo
 
Posts: 17
Joined: Fri Nov 27, 2009 12:46 am

Re: [Example] Relations reflected by list boxes in forms

Postby RoryOF » Fri Apr 22, 2011 9:54 pm

If you do not wish to read any particular person's postings, adjust the settings in your Forum User Control Panel. As you are not getting answers to how to do what you want, consider that it may not be possible.
Apache OpenOffice 4.1.4 on Xubuntu 16.04.03 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 25716
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Example] Relations reflected by list boxes in forms

Postby ubiquity » Mon Aug 27, 2012 4:26 pm

Thank you for these important considerations Villeroy.
As an MS Access user from its beginning and RBase & dBase before that, the information here is invaluable.
Although I enjoy using MS Access (poorly) it is now getting beyond my (virtually retired) pocket.
To be fair to MS Access it is 'flexible' but that really means that you can be a bit 'sloppy' with your design (particularly with regard to normalisation) so I was a little under-prepared when taking my first tentative steps with Base as the interface to HSQLDB.

In particular I, and I suspect many other Access users, was used to being able to use combo boxes with multiple visible fields and selectable bound fields.
It was extremely useful to find the explanation of List Boxes for that purpose here, especially given the limited and specialised use of list boxes in access by comparison.

I am progressively going through the other material you have listed and uploaded to begin to refocus my mind on good design first, before attempting to build systems in an ad hoc fashion as one is tempted to do in Access.

Thanks again. :bravo:
OpenOffice 4.1.1
Windows XP Sp3
User avatar
ubiquity
 
Posts: 20
Joined: Fri Aug 24, 2012 3:23 am
Location: Tasmania, Australia

Re: [Example] Relations reflected by list boxes in forms

Postby papijo » Sat Nov 08, 2014 6:02 pm

Hi Villeroy and thanks for your detailed tutorial and the concrete example attached as relations2listboxes.odt.

Just wanted to let you know that the multiple select table Many T_IDS needs some refinement. It does not prevent the user from adding more than one identical "Thing" element from its dropdown list. As a consequence, if user navigates to the next (or previous) record, that extra element is automatically and silently removed, which is OK.
However, if, instead of navigating to another record the user clicks the Save record button, an error message is issued:
"Error inserting the new record. Violation of unique constraint SYS_PK_85: duplicate value(s) etc."
Any suggestions?
Thanks in advance.
LO: LibreOffice 5.2.3 on Windows 10 64bits. Split database HSQL 2.3.4.
papijo
 
Posts: 86
Joined: Sat Nov 08, 2014 5:46 pm
Location: Brittany, West of France


Return to Database Examples

Who is online

Users browsing this forum: No registered users and 1 guest