Passing parameters from form to query

Discuss the database features
Post Reply
joaofmateus
Posts: 33
Joined: Fri Mar 20, 2009 12:15 pm
Location: Lisbon - Portugal

Passing parameters from form to query

Post by joaofmateus »

I have a forms where I write:

Enter the starting date ------>
Enter the ending date ------->

I have this query:

Code: Select all

SELECT "COD_CONTA" AS "CONTA", SUM ('DEBITO) AS "DEBITO", SUM ("CREDITO") AS "CREDITO" FROM "tMOVIMENTOS_CONTA" AS "tMOVIMENTOS_CONTA" WHERE "DATA_MOV" >= :DATAINICIAL AND "DATA_MOV" <= :DATAFINAL GROUP BY "COD_CONTA
I wanted to pass parameters from forms to the query.

Would somebody could help me?
 Edit:  
Last edited by Villeroy on Thu Jun 02, 2011 10:26 pm, edited 1 time in total.
Reason: added code tags
OOo 4.1.5 on MS Windows 10
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: Passing parameters from form to query

Post by rudolfo »

I wish there would be a less complicated answer to this, but I fear you won't be able to achieve this without macros. Here is an outline on how to do this (it is difficult to be more precise, because this depends on how you want to start the macro, button click, ...?)
  • Retrieve the connection from the active DataSource
  • Use the prepareCommand() method of the connection to create a prepared statement based on the query
  • Retrieve your two date values from the current record of the form
  • Bind these two variables to the place holders in the query (Note: Date parameters need to be of type "com.sun.star.util.Date" UNO structure: stmt.setDate(1,aBegin) and stmt.setDate(2,aEnd))
  • Execute the prepared statement to retrieve a result set
  • Iterate through the result set and use the getString() and getLong() to read the resulting fields into variables of your scripting language.
Using result of Queries has some OOo Basic code that might be good enough for you after some modifications.

I can give you some sample code, once you have decided to go the macro way. But be aware that you need some programming experience because most probably you will have to make some modifications to match it on you environment. And without experience (including debugging a macro) this will all be like chinese for you.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Passing parameters from form to query

Post by Villeroy »

Have a look at the attachment.
Attachments
ListData2.odb
Filter by date and categories, aggregate values
(79.22 KiB) Downloaded 1789 times
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