[Solved] Refresh/Reload Dropdown List

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
jmadero
Posts: 62
Joined: Sun Nov 15, 2009 10:04 pm

[Solved] Refresh/Reload Dropdown List

Post by jmadero »

DB: https://drive.google.com/open?id=1kCiKT ... PX4nMR3i4E

Steps:
(1) Open MyLibrary form;
(2) Click New Author;
(3) Add an author;
(4) Check related drop down on MyLibrary form;

Observed: New addition not included.

What I'd like is a macro that runs from the New Author form where after a new author is added, the dropdown is refreshed/reloaded so I don't have to close and reopen the form to see the new book.

Thanks in advance
Last edited by jmadero on Fri Jul 20, 2018 11:06 pm, edited 1 time in total.
Bodhi 5.0, LibreOffice 6.0.5.2, and OOo
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Refresh/Reload Dropdown List

Post by Villeroy »

viewtopic.php?f=21&t=88831 refreshes one or many list boxes, combo boxes or forms after the current record some (sub-)form has been updated, deleted or inserted.
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: 1547
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Refresh/Reload Dropdown List

Post by UnklDonald418 »

When you close the New Author form and control returns to MyLibrary, MyLibrary is unaware that you made any changes.
An alternative to Python macro is to add another Button control to MainForm with the Action property set to Refresh form.
After entering a new author press the Refresh button to see your addition in the list box choices without exiting MyLibrary.
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
jmadero
Posts: 62
Joined: Sun Nov 15, 2009 10:04 pm

Re: Refresh/Reload Dropdown List

Post by jmadero »

I'm a bit confused by the instructions in the example:
2. Use the form navigator to add a new hidden control named "AutoRefresh" (case sensitive) to the "NewMovie" form (or to the "NewGenre" respectively) and add the following hierarchical path to the item you want to refresh, so the value reads ../MainForm/SubForm/SubForm_Grid/MovieID (or with trailing /GenreID if you are editing the other form).
I don't see a "NewMovie" or "NewGenre" form. I only see these three forms:
(1) Genre_Movie;
(2) Movie_Genre;
(3) Movies_flat
Bodhi 5.0, LibreOffice 6.0.5.2, and OOo
jmadero
Posts: 62
Joined: Sun Nov 15, 2009 10:04 pm

Re: Refresh/Reload Dropdown List

Post by jmadero »

UnklDonald418 wrote:When you close the New Author form and control returns to MyLibrary, MyLibrary is unaware that you made any changes.
An alternative to Python macro is to add another Button control to MainForm with the Action property set to Refresh form.
After entering a new author press the Refresh button to see your addition in the list box choices without exiting MyLibrary.
The only problem with this method is that it clears the form. So let's say I'm putting in a book, I think I've already read something by the author so I've put in the title, page number, etc . . . then I get to author and I'm like "oh shoot, I need to enter this author" - this method would make it so the form is cleared and I have to start from scratch.

It's functional for now but ideally I'd like just the individual drop down to be updated.
Bodhi 5.0, LibreOffice 6.0.5.2, and OOo
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Refresh/Reload Dropdown List

Post by Villeroy »

--- this has become obsolete ---
Last edited by Villeroy on Fri Jul 20, 2018 1:52 pm, edited 1 time in total.
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: 1547
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Refresh/Reload Dropdown List

Post by UnklDonald418 »

The only problem with this method is that it clears the form.
On the Refresh button set the Action to None, and execute this macro from the Approve action event on the button

Code: Select all

REM  *****  BASIC  *****

Sub ReloadAuthor(oEvent as object)

oForm = oEvent.Source.Model.Parent
oControl = oForm.getByName("Author")
oControl.Refresh()

End Sub
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
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Refresh/Reload Dropdown List

Post by Villeroy »

I'm sorry for the desaster. I replaced a former AutoRefresh macro with a newer, simplified version and now the description does no longer match the macro. The old version used the forms "record action" event and reads settings from a hidden control. The new one uses the push button's "approve action" event reading the setup from the "additional info" of the same button. Yesterday I exchanged the code and the install instruction but not the usage instruction because I was not aware of 2 different macros with the same names. Shame on me.
All the trouble started when I replaced the old version with the new one without renaming the files and routine. Many months later I stumbled upon this carelessness. Before publicing the new version I should have renamed the new files and the calling routine.

@ jmadero
Replace the AutoRefresh.py you've installed yesterday with the one from the zip file and keep your form setup with the hidden control "AutoRefresh". It is the macro with the hidden control and form event.

--- some text about the new version removed ---
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
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Refresh/Reload Dropdown List

Post by Villeroy »

I revoke the new one. It does not work the way it should. It works with its own push button but not event driven because the button first runs the macro and then it updates/deletes/inserts the record. It would work as desired if the push button could do its action first and then run the macro.

The original AutoRefresh.py code triggered by the "form action" event and reading its configuration from hidden control "AutoRefresh" works event driven without additional push buttons. Whenever you saved or removed a record one way or the other [*], it refreshes the configured form elements.
[*]by moving away from a modified record, by using a push button, context menu, toolbar button or whatever

I put the old code into an installer document. Everything else remains the same as before. After you installed the macro to Scripts/python/pyDBA/AutoRefresh.py the here attached movies database uses that code to refresh the Genres list box on the Movies_Genres form and the Movies list box on the Genres_Movies form.

Python installer: download/file.php?id=35499 (tested with forms and list boxes)
Attachments
movies_pyRefresh.odb
movies_5.odb with AutoRefresh.py dependency
(31.6 KiB) Downloaded 186 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
jmadero
Posts: 62
Joined: Sun Nov 15, 2009 10:04 pm

Re: Refresh/Reload Dropdown List

Post by jmadero »

You guys are both awesome. Still working through some kinks but this DB is coming together really nicely. If either of you are interested in checking it out...the only form that is really complete is the MyLibrary one but functionality is largely there already.

DB: https://drive.google.com/open?id=1kCiKT ... PX4nMR3i4E
Bodhi 5.0, LibreOffice 6.0.5.2, and OOo
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Refresh/Reload Dropdown List

Post by Villeroy »

Just another example with and without AutoRefresh.py plus a form with a categorized listbox as a simple alternative.
viewtopic.php?f=100&t=94393
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