# Create report based on inputs of current form - LO Base

How do you compose a macro to open a report based on the inputs from the current form?

The database is tracking different peoples expenses, so the form includes the persons name, address, phone number, and there is another subform that includes their purchase and the price of it. Now what I would like is to have a button when pressed would create a report that has only the information on the current form that I am working on (NOT all of the records (or forms) I have created, which is what is happening now).

The following question, https://ask.libreoffice.org/en/questi... is trying to accomplish something very similar but it has many entries on the form and a report is made out of the one that is selected by the user.

I am aware I would have to use a macro but not too sure how I would go about it! I am using version 5.2.6.2

edit retag close merge delete

Sort by » oldest newest most voted

You say to press a button to generate a report base upon screen content. Is this before or after the data is saved & how is it known it is saved?

The button is pressed after the data in the form is saved and there is a button that saves the record

Does the subform have one or multiple records and if multiple are they all to be printed?


The subform has multiple records and yes they are all to be printed, this contains all the purchases and the price

One possibility you may want to pursue is a simple flag in the record if it is to be printed. Then the query used would only select those records where the flag was set.


This is similar to what I wanted to do, create a query that would only take the values of the current entry ID, but I am not sure how to do this

more

Your question as presented leaves open quite a number of questions. You statement about using a macro is one. The question here is are you knowledgeable in writing macros? If not, it is a major task in itself to learn all the necessary workings.

The majority of questions are really about procedure. You say to press a button to generate a report base upon screen content. Is this before or after the data is saved & how is it known it is saved? The Base form contains a form and subform. Does the subform have one or multiple records and if multiple are they all to be printed? This may only be some of the possible questions you should be looking at.

One possibility you may want to pursue is a simple flag in the record if it is to be printed. Then the query used would only select those records where the flag was set. Of course once the record was printed, this flag would need to be cleared. Again, possibly a macro.

A macro for the procedure you specify may be to grab each of the individual fields needed (with proper code), write them to a table just for this purpose and then execute the report based upon that special table. This table should be cleared of any records just before each use within the macro.

Actually creating this kind of macro, as your opening question states, would require most if not all of the Base & database information, a lot of question answering and possibly some considerable amount of time.

Edit 6/21/17:

Just to save a bit of back & forth I attached a sample which is based upon parameter selection. The database is set with two customer records: 1 & 2. If you run Report1ByCust you will enter a 1 or 2 to print report. Those two customers are set with three different invoices (quick & dirty set-up - would not normally do this way; just a demo). Cust #1 has Invoice #1111 and Cust #2 has Invoice #3333 & 4444. Running Report2ByInvoice you will enter one of these three invoice numbers.

Sample: CustomerSelectForPrint.odb

more

( 2017-06-21 07:31:28 +0100 )edit

@cleo27 You never did answer the first & important question about knowing how to code macros. This is a basis for asking some of the questions. But let's take the non-macro approach. Since you haven't stated, it's an educated guess on the form. You have a master record, a customer. The subform seems to be items purchased. Can this customer be used again for a different purchase? My guess is yes. If so what tells you the subform data belongs to what purchase? More details on content.

( 2017-06-21 09:10:45 +0100 )edit

If you did not re-use the customer information, this would simply be a matter of changing the query into the report to have a parameter for input. You then enter the customer ID you wish to print & only that master record with its' associated records of the detail are printed. This, of course does not seem logical. So it appears there may be some associated information maybe regarding an invoice number or something similar. That is what is missing - what makes the screen info unique?

( 2017-06-21 09:23:31 +0100 )edit

1.You don't necessarily have to create a macro for this.

You can base your report on a query which accepts parameters when you run it.

In the case you describe the parameter would be what is sufficient to narrow the result set to only those records related to a particular person: So either a PersonID (wich is problematic because we likely don't remember some random number) or a unique name.

Now, you could write a macro that supplies the answer to the query quietly when you execute the macro with the form open.

OK so first thing is, How to add a replaceable parameter to a query, quite simply by prefixing a : character.

Here is a picture of a simple query that does this

The first thing I would do then is to look at the query, if you are using one, that your form is based on and see if there is an obvious way to use that trick, if so then you could look at using the macro to automate it eve further.

more