[Solved] Changing default value of listbox revisited

Discuss the database features

[Solved] Changing default value of listbox revisited

Postby gkick » Sat Sep 28, 2019 5:35 am

As per previous post setting/changing the default value of a listbox via route of a filter table works perfectly. Done a little more searching as I really would like to set the default of a listbox (contained in grid) without filtering the grid, sort of similar but not the same as the Clone RecordDB. Ideally the listbox would display the previous records value in the new record.
One thought, not sure if practical would be once the listbox in the grid changes its value run
ALTER TABLE "tblAssets" ALTER COLUMN "Category" SET DEFAULT ...= the current integer value, but I guess I need to capture that value by way of a variable ?

Thanks
Last edited by gkick on Mon Sep 30, 2019 4:34 am, edited 1 time in total.
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
gkick
 
Posts: 268
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

Re: Changing default value of listbox revisited

Postby UnklDonald418 » Sat Sep 28, 2019 6:29 pm

While not exactly what you are asking, look at this alternative approach
Base Copy Field or Clone Record - Example
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.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1337
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Changing default value of listbox revisited

Postby Villeroy » Sat Sep 28, 2019 11:42 pm

Ideally the listbox would display the previous records value in the new record.


With Form2 of my download/file.php?id=22304
sort the main form by ID in descending order so the latest record is on top when you refresh the form. Simply append ORDER BY "ID" DESC to the underlying query.
Apply my AutoRefresh macro to the subform and let it refresh the parent form [*]. This should apply the defaults according to the parent form's first record which is always the active record after a refresh. Now you may even hide the visible controls of the parent form.
When you tab through the subform, it will be saved after the last control, the macro will be triggered, the parent's active record will be the just added one and the subform's new record inherits the right values.

[*] Add a hidden control "AutoRefresh" to the subform with .. as value. The two points refer to the parent.
Assign the form's "after record action" event to the auto-refresh macro.

 Edit: See attached defaults3.odb if you still have my AutoRefresh installed. 
Attachments
defaults3.odb
(50.04 KiB) Downloaded 40 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28650
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Changing default value of listbox revisited

Postby gkick » Sun Sep 29, 2019 3:43 am

You guys are real great, helpful, nice, walking manuals,.....

Appreciate your ideas, suggestions, the samples in particular as I understand best by way of reverse engineering.

@ UnklDonald418
Thanks for the links, certainly worth keeping for another project. Unfortunately the Alt+ does not work on my exotic Notebook and possibly at other machines.

@Villeroy
Form1 is just perfect with the exception that records are cleared when changing the default as the new filter takes effect. Form2 I could not figure out.
Now the thing also is that a couple of my forms have in excess of 10 Listboxes each and for all of them I would like to implement change of default. I somehow feel that adding all the references into the hidden control might add up to a string of a kilometer and possibly impossible to debug if there is a mistake. One form has form, subform and seven tablecontrols the Listboxes being everywhere.
As such I think and I maybe wrong the most practical way might be to change the fields default via SQL once the listbox value changes. But I have no idea how to achieve this getting the integer value into a variable and then pass this variable into an SQL string, let alone not sure if this can be done nor the implications on performance.
Made some screendumps but only attach one as the others exceed the 128 limit, Dropbox is a problem here as Internet connection is very flaky except at 4 am.
Thanks again for your tireless assistance.
Attachments
contactsaddedit.JPG
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
gkick
 
Posts: 268
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

Re: Changing default value of listbox revisited

Postby Villeroy » Sun Sep 29, 2019 10:06 am

My solution does not refresh list boxes. It refreshes the single parent form where the default values come from. It does not matter how big or how small that parent form is.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28650
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Changing default value of listbox revisited

Postby UnklDonald418 » Sun Sep 29, 2019 6:11 pm

The Alt+ key combination can easily be changed to something else.
Looking at the macro, there are two lines that determine which key combinations to respond to
Code: Select all   Expand viewCollapse view
   IF  (oEv.KeyCode=1287 AND oEv.Modifiers=4) THEN CloneAnyRecord(oEv) : Exit Sub
   IF  NOT(ASC(oEv.KeyChar)=39 AND oEv.Modifiers=4) THEN Exit Sub

the value 1287 is for the + key (ADD) and the Modifiers value of 4 is the Alt key. You could change the 1287 to a different value from the list found at
https://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/Key.html
Be careful not to use a value that has already been assigned. Go to Tools>Customize>Keyboard to see which key combinations are already being used.
As I mentioned the Modifiers value of 4 is the Alt key on a windows keyboard. For a list of Modifiers see
https://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/Key.html
The macro also uses the value 39 (decimal ASCII value for the Apostrophe key) to trigger the copy field macro. That too can be changed.
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.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1337
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Changing default value of listbox revisited

Postby gkick » Mon Sep 30, 2019 4:33 am

Thank you UnklDonald418 , I actually changed the macro to use the ESC Key only (ESC doesn t seem to do anything in Base, alternatives could be Del or INS) works fine in tablecontrols - one problem solved thanks you for the pointers. The pk is no problem as not shown in the tablecontrols.
But funny if I use 1281 for ESC the macro throws up an error, if I use 27 which I use in my Flightgear project, the macro works fine.

To implement a default for standard forms 1rec at a time, I have been on the wrong path all along as changing the default in the table does not effect the behaviour of the listbox.

What I need to do instead is to set the default of the listbox with the value of another listbox
So all whats needed is a mainform with lstCountry plus another listbox on a sub or tablecontrol named lstCountryDefault and using pseudocode once the lstCountryDefault is changed use an event to something like
lstCountry(default property) = integervalue of lstCountryDefault
I ll figure that one out eventually, for now I mark this topic as closed since multiple solutions.
Thank you all for your guidance on this.
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
gkick
 
Posts: 268
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile


Return to Base

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest