0

I created a database Form with 2 comboboxes, Combo1 and Combo2. Combo2 visibility depends on Combo1 status: Combo1 checked, Combo2 visible; Combo1 unchecked, Combo2 hidden.

I expected to find something like Combo2.setVisible(Combo1.isVisible()) but I have been too optimist.

This is the macro I have been playing with:

Sub MyMacro(oEvent as Object)
    msgbox(oEvent.Source.getState())   rem returns Checked/Unchecked status of Combo1
    msgbox(oEvent.source.model.Name)   rem Name of the Event generator (Combo1)
End Sub
cb2 = ThisComponent.Drawpage.Forms.getByName("MainForm").getByName("Combo2")
msgbox(cb2.Name)

prints correctly Combo2, so I assume I have a proper reference...

And now?

Today is the very first day I play with Libreoffice Base (and its bugs), and this is just something nice that I would like to add for tomorrow's demo. I NEVER used before a macro both in Microsoft nor Libreoffice suites, so I am moving veeery slow.

Last time I used BASIC was probably around 1990.

I went through a number of tutorials online (usually based on Libreoffice Calc cells), string-searched both main books by Andrew Pitonyak ("Useful Macro Information For OpenOffice.org" and "OpenOffice.org Macros Explained (OOME)") but after trying tons of snippets I got nowhere.

Same for libreoffice macro - toggle enablevisible on a textfield

Any pointer?

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Alex Poca
  • 2,406
  • 4
  • 25
  • 47
  • If you are uncomfortable with Basic, then try [Python](https://wiki.openoffice.org/wiki/Python/Transfer_from_Basic_to_Python) which is a popular macro language for LibreOffice. [APSO](https://extensions.libreoffice.org/extensions/apso-alternative-script-organizer-for-python) helps get started. – Jim K Mar 06 '20 at 10:38
  • 1
    Can't answer your specific Q, but if you're going to be using base basic, I think you really need to be using this if you aren't already: https://extensions.libreoffice.org/extensions/mri-uno-object-inspection-tool It took me a little while to learn to use it, and I even then rewrote the manual for it a bit, but I found it very helpful. Here is the best manual for it: https://github.com/hanya/MRI/wiki – Elliptical view Mar 10 '20 at 16:37

1 Answers1

0

This is a working snippet (not guaranteed to be the most straightforward, as my experience with macros is one day long):

Sub SetVisibility(oEvent as Object)
    cb2 = ThisComponent.Drawpage.Forms.getByName("MainForm").getByName("Combo2")
    cb2.enableVisible = oEvent.Source.getState()   
    rem the action is activated by Combo1, the event source
End Sub
Alex Poca
  • 2,406
  • 4
  • 25
  • 47