[Solved] Identifying a record via a listbox

Creating and using forms
Post Reply
douginchis
Posts: 5
Joined: Mon Nov 15, 2010 7:02 pm

[Solved] Identifying a record via a listbox

Post by douginchis »

I populate a listbox via an SQL statement which delivers 2 fields: a record ID, and a name. I want the user to select the name in the listbox. Is there any way I can then pick up the record ID in a macro?
Last edited by douginchis on Thu Nov 18, 2010 7:10 pm, edited 1 time in total.
XP OpenOffice 3.2
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Identifying a record via a listbox

Post by Villeroy »

This is what listboxes use to do without any macro.
Data properties of the list box:
Data field: The foreign key field where to put the ID
Type of content: SQL
Content: SELECT "Name","ID" FROM "Table" ORDER BY "Name"
[or type=Query and some query name with a similar content]
Bound field: 1 [always 1 since 0 is the visible field]

Install the MRI extension and bind some event to Basic MyMacros>MRI>mri
Find out how to get the value you need.
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
douginchis
Posts: 5
Joined: Mon Nov 15, 2010 7:02 pm

Re: Identifying a record via a listbox

Post by douginchis »

thanks, will give it a go and come back to mark Solved
XP OpenOffice 3.2
douginchis
Posts: 5
Joined: Mon Nov 15, 2010 7:02 pm

Re: Identifying a record via a listbox

Post by douginchis »

List box works fine from my query or SQL, but as soon as I put any entry in Data Field, then list box becomes frozen greyed field in the form. This is the same whether the list content is an SQL statement or a query. And x-ray of data field shows null string.
XP OpenOffice 3.2
douginchis
Posts: 5
Joined: Mon Nov 15, 2010 7:02 pm

Re: Identifying a record via a listbox

Post by douginchis »

OK I have tried to read everything I could find in the forum about listboxes, and I hope I have figured it out. I state it here in order to check if I have got it clear, and maybe help other newbies, like me who are converting from Access.
A listbox really expects to be bound to a data field in a recordset to which the form, containing the listbox is bound. So, unlike listboxes in Access, you can only get at other fields in the rows which populate the listbox, by using one of them to update a field in the recordset which is bound to the form.
Maybe I should be trying a different technique. What I am trying to do is to allow the user to pick a customer, then click command buttons to run any of a series of reports for that customer. I want to pick up the customer ID to simplify setting up and running whichever report is selected. Any ideas of the best way to do this in OOBase, anyone?
XP OpenOffice 3.2
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Identifying a record via a listbox

Post by Villeroy »

You can also fill an unbound list box and read out the content by macro. But why?
Store your user selection in a distinct record of some dummy table and build queries like:
SELECT * FROM "Data" D, "Filter" F WHERE D."ClientID"=F."IntVal" AND F."ID"=0

A demo with some tables, relations and several filtering forms/subforms:
http://user.services.openoffice.org/en/ ... hp?id=9701

A single form/subform with textual filter, query and report based on form content:
http://user.services.openoffice.org/en/ ... hp?id=6442
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
Arineckaig
Volunteer
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Identifying a record via a listbox

Post by Arineckaig »

A demo with some tables, relations and several filtering forms/subforms:
download/file.php?id=9701
If you are feeling strong and a glutton for punishment a detailed set of notes explaining this filter demonstration database can be downloaded from:
http://dl.dropbox.com/u/10552709/FilterExamples.zip
It is, however, very much work in progress and subject to edit each time I find errors and omissions.
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Identifying a record via a listbox

Post by Villeroy »

http://dl.dropbox.com/u/10552709/FilterExamples.zip
YES! This is it.
One addition to "Use of Navigation Toolbar with multiple Data Forms":
In the data properties of a form you can declare that the navigation toolbar should be never shown or that the toolbar should refer to the parent form. When there is a single detailed record in a subform or just a small record set in a grid you don't really need the tools. I like the parent form option because it helps to make the form appear as one unit.
What you call "power filtering" can be set up with no tool bar for the parent form which refers to a single record in most cases.
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
Arineckaig
Volunteer
Posts: 828
Joined: Fri Nov 30, 2007 10:58 am
Location: Scotland

Re: Identifying a record via a listbox

Post by Arineckaig »

One addition to "Use of Navigation Toolbar with multiple Data Forms"
Thank you Villeroy for these helpful points. I will try to incorporate it in a later version: that section certainly needs more thought and filling out.
When this issue has been resolved, it would help other users of the forum if you add the word - [Solved] - to the Subject line of your 1st post (edit button top right).
AOOo 4.1.5 & LO 6 on MS Windows 10 MySQL and HSQLDB
douginchis
Posts: 5
Joined: Mon Nov 15, 2010 7:02 pm

Re: Identifying a record via a listbox - solved

Post by douginchis »

thanks, will work on these ideas
XP OpenOffice 3.2
Post Reply