[Solved] Change control property based on SQL output

Discuss the database features
Post Reply
1gatomontes
Posts: 20
Joined: Sun May 14, 2017 3:48 am

[Solved] Change control property based on SQL output

Post by 1gatomontes »

I would like to have the property (background color) of a control (list box for example) change (upon form refresh) based on a number (ex: 1=red, 2=green, etc). This number is the result of a SQL snippet (which currently works) counting the number of rows in a table.

After looking for an easy solution, I'm now afraid that my only solution will be to turn to macros to do this, right? If so, any help would be appreciated, because macros is a very obscure world to me.

Thank you all!
Last edited by 1gatomontes on Tue Oct 17, 2017 8:57 pm, edited 1 time in total.
OpenOffice 4.1.2
Windows 10 (v.1607)
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Change control property based on SQL output

Post by Villeroy »

Formatted controls behave like spreadsheet cells with numbers.
F1-help on number format codes wrote:[BLUE][<0]#,0 "°C";[RED][>30]#,0 "°C";[BLACK]#,0 "°C"
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
1gatomontes
Posts: 20
Joined: Sun May 14, 2017 3:48 am

Re: Change control property based on SQL output

Post by 1gatomontes »

Thanks Villeroy, but this is too limited (up to 3 codes only) for our purpose, or am I getting the limitation wrong?
OpenOffice 4.1.2
Windows 10 (v.1607)
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Change control property based on SQL output

Post by Villeroy »

Yes. Seems to be so. A macro could do the trick for single controls. Nothing can not colour individual lines in a grid control.
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
UnklDonald418
Volunteer
Posts: 1549
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Change control property based on SQL output

Post by UnklDonald418 »

I was recently working on a project that needed something similar to what you are asking so I put together a little demonstration of how a macro might work to solve your problem. The macro would probably need further massaging but at least it is a starting point.
Attachments
DemoColorByValue.odb
(14.13 KiB) Downloaded 131 times
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Post Reply