Page 1 of 1

Create duplicate records based on field value

Posted: Sun Sep 13, 2020 1:43 am
by christos73
Hello forum!

I have an table : tblDetails that has the following fields named :

Barcode (Number)
Price1 (Number)
Price2 (Number)
etc...

What i want is when i enter data in my form, suppose i enter in Price1 the value :"1.99" i want to be copied - mirrored in Price2 field (automatically.

So when i step in Price2 i would leave it unchanged or i'll enter what value i like to.

Does anyone knows how i can mirror Price1 value onto Price2?

Thank you and have a nice day!

Re: Create duplicate records based on field value

Posted: Sun Sep 13, 2020 12:23 pm
by Villeroy
Make "Price2" optional (nullable) but not "Price1". Then use the value of "Price1" when "Price2" is missing.

Code: Select all

SELECT "Table".*, COALESCE("Price2","Price1") AS "P2" FROM "Table"
selects all columns plus the "true Price2" AS "P2".

Re: Create duplicate records based on field value

Posted: Sun Sep 13, 2020 3:21 pm
by christos73
Hello Villeroy,

See my screenshot:

So i'am looking something like this https://ask.libreoffice.org/en/question ... r-a-field/ but it' doesn't work in base.

Re: Create duplicate records based on field value

Posted: Sun Sep 13, 2020 3:51 pm
by Villeroy
Just keep it blank if the prices are the same. Add some explanatory text to the label such as "(blank if same price)"

Re: Create duplicate records based on field value

Posted: Sun Sep 13, 2020 5:41 pm
by christos73
Ok it works through the query. But the field "V2" still remains empty in Tables.
I need the "Value2" from Query1 to be transferred into "V2" field.
I must make relation between these two fields!

And query is not the solution for me. Because when the second field which is ""Price2" has different cost value, if i run the query it will replaced by Price1 which I don't want.

Thanks for your time!