Friday 2 April 2010

Creating reports based on user input criteria in OpenOffice BASE

I was searching the Open Office Community forum to solve a problem but did not find a direct answer. However I think I have worked out a method so I thought I would share it.
My development rig is using standard OO DB drivers. My production rig is using MySQL on our domain server to allow shared access.
I am using 3.1.0 on the development rig Windows 7 based. I am hoping my production rig will work from Windows and Linux platforms.
It is only a small database taking over from a spreadsheet which is getting too unwieldy to work.
I have 3 tables:-
Clients: clientno, name, contact, addr1, addr2, postcode
Record types: recordno, typename
Details: recordno, recordid, clientid, username, password, url, extra

Details.clientid = Clients.clientno
Details.recordid = Records types.recordno

I want to be able to generate a report which extracts from the DB all records pertaining to a particular client and allow the user to enter the client name after selecting the report to run. [Ideally I would like to do this selection from a form but I will live with what I have got at the moment]

I have in the past written db programs using basic ISAM files. I have recently been writing web apps using MySQL DBs so I had a good idea of how I wanted my solution to look. I just wasn't getting how to do it in OO and I have never found the patience to work through MS Access.

My solution.

I created a view with all the fields from the Detail record with links to the relevant tables elsewhere and saved this View as 'Details View'.

Next I went to queries and set up a new query. When I got to the Search Conditions I selected View.clientname in the fields box put in " :Enter_Client_Name " in the values box as suggested elsewhere in this forum but without the double quotes [and this point is important].
I then completed the query. When I ran it it gave me an empty list. I went back in to 'edit by SQL' and noted that the SQL had placed my :Enter_Client_Name in single quotes and thus it was not being found. I took off the single quotes [please note the input field turned green at this point]. Running this query allowed me to input the client name successfully.

Then I set up a report using this new query as the basis of the report. Running the report now allows the user to enter the name of a client on which they want to generate a report.

I am not going to say that I may not need refinements on this but I do believe that this gives other newcomers to OO DB a chance to make progress. Given a number of the posts on the forum I feel this is at the base of a lot of the queries.

The original post can be found on the OpenOffice.org Community Forum at this web address http://user.services.openoffice.org/en/forum/

Many thanks to all contributers to that forum.

No comments: