List box not updating field with bound value

I know this is complicated, but I'll try to be simple and clear.

I'm building a form that displays a single record at a time from a table, as a set of text boxes. The form displays all data in the table by moving successively to each record. Every field except the primary key field can be edited.

I have a list box bound to one of the fields. It displays a field from another table (which has only a key field and a data field - text). That table has only a few records. It's sole purpose is to contain the list to be display in the list box.

My intention is that selecting a value from the list box will cause the field in the main table to be updated by the key of the record containing the selected list item in the list table. That key is field #1 in that table, so my bound value is 1.

The list is displaying perfectly. However, in the form, the field to which the list box is bound displays nothing, ever. It DOES initially have a value, and certainly should after I make a list box selection. It just never shows any value, however. Moreover, looking at the main table's record outside of the form shows that it contains only "0", regardless of which list item I select.

So...

1. Why is no value ever displayed in the form, even though there IS a value in the record? In MS Access, it would show, I believe.
2, Why is the selected list item's key never updated into the master table field. It IS bound, according to the property dialog.

I don't see my error, I'm afraid. Any suggestions would be appreciated.

Hi Tom,

Possibly any one of these might shed some light :

http://openoffice.org/bugzilla/show_bug.cgi?id=96703

http://www.oooforum.org/forum/viewtopic.phtml?t=55208

http://plan-b-for-openoffice.org/ooo-help/r2.1/en-US/WIN/shared/02/01170203

http://user.services.openoffice.org/en/forum/viewtopic.php?f=13&t=3619&p=16752

HTH,

Alex

I know this is complicated, but I'll try to be simple and clear.

I'm building a form that displays a single record at a time from a table, as a set of text boxes. The form displays all data in the table by moving successively to each record. Every field except the primary key field can be edited.

Are you using Calc or Base??
And do you automatic initialise the form ore do you use a macro to initialise the form and fill it with contents?

I have a list box bound to one of the fields. It displays a field from another table (which has only a key field and a data field - text). That table has only a few records. It's sole purpose is to contain the list to be display in the list box.

My intention is that selecting a value from the list box will cause the field in the main table to be updated by the key of the record containing the selected list item in the list table. That key is field #1 in that table, so my bound value is 1.

The list is displaying perfectly. However, in the form, the field to which the list box is bound displays nothing, ever. It DOES initially have a value, and certainly should after I make a list box selection. It just never shows any value, however. Moreover, looking at the main table's record outside of the form shows that it contains only "0", regardless of which list item I select.

So...

1. Why is no value ever displayed in the form, even though there IS a value in the record? In MS Access, it would show, I believe.
2, Why is the selected list item's key never updated into the master table field. It IS bound, according to the property dialog.

It would bee much easier to help you if you put the document online, so everybody can test it and see what is the best solution for your problem
1.There is a big difference between MS Listboxes and LO-Listboxes.
In MS you can address items in a list-box by there key number, in LO only by there name.
2.You can connect a simple macro to the "list-box-change" event that updates the master table field.

I don't see my error, I'm afraid. Any suggestions would be appreciated.

I'm not sure, if my suggestion is really what you want.

Hi :slight_smile:
Hopefully this is in Base rather than Calc. The 2 tables need to be connected
by some sort of relationship. I don't think spreadsheets work as relational
databases? One of the 'obvious' 'easy answers' (and therefore most commonly
missed) is if the relationship is not defined in Base. It might be defined in
Access but it's worth checking that Base shows the same thing.

Thanks and regards from
Tom :slight_smile:

Thanks much for these links. Will dive into them as soon as I can.

t.

I know this is complicated, but I'll try to be simple and clear.

I'm building a form that displays a single record at a time from a table, as a set of text boxes. The form displays all data in the table by moving successively to each record. Every field except the primary key field can be edited.

Are you using Calc or Base??
And do you automatic initialise the form ore do you use a macro to initialise the form and fill it with contents?

Ooops. Sorry. Am using Base.

No initialization is needed, as the controls on the form are linked to db records fields, and the form opens showing the first record in the main form (if there's more 6than one).

I have a list box bound to one of the fields. It displays a field from another table (which has only a key field and a data field - text). That table has only a few records. It's sole purpose is to contain the list to be display in the list box.

My intention is that selecting a value from the list box will cause the field in the main table to be updated by the key of the record containing the selected list item in the list table. That key is field #1 in that table, so my bound value is 1.

The list is displaying perfectly. However, in the form, the field to which the list box is bound displays nothing, ever. It DOES initially have a value, and certainly should after I make a list box selection. It just never shows any value, however. Moreover, looking at the main table's record outside of the form shows that it contains only "0", regardless of which list item I select.

So...

1. Why is no value ever displayed in the form, even though there IS a value in the record? In MS Access, it would show, I believe.
2, Why is the selected list item's key never updated into the master table field. It IS bound, according to the property dialog.

It would bee much easier to help you if you put the document online, so everybody can test it and see what is the best solution for your problem
1.There is a big difference between MS Listboxes and LO-Listboxes.
In MS you can address items in a list-box by there key number, in LO only by there name.

Um. Where in the world is this documented. I don't quite get it - and example would help, and the only one I've found looks inappropriate. It uses a list box simply to fill a field, not to insert a key which points to the field, and THAT's what I want. NOT to do this would de-normalize the database, would it not? So why would I EVER do that?

2.You can connect a simple macro to the "list-box-change" event that updates the master table field.

I don't see my error, I'm afraid. Any suggestions would be appreciated.

Well, maybe you could. I don't know where to start. I'm a ruby programmer (barely), and the object model of LO Basic (or whatever it's called) is completely unknown to me. Is there an example of this somewhere?

I'm not sure, if my suggestion is really what you want.

Well, if I understand you, I think you're on target. It certainly moved my thinking forward.

Thanks!

Tom

Hi :slight_smile:
Hopefully this is in Base rather than Calc.

Good guess...since I didn't exactly say. Sorry.

The 2 tables need to be connected
by some sort of relationship.

One would think. Yet, use of the Tools > Relationship functionality makes no difference at all to my results. I find that amazing. I guess Frieder got it right when he said that list boxes in LO simply supply contents, and NOT record keys. Not good, if true, although that IS what appears to be happening. It would also account for the non-persistence of my list box selection. A text field placed into an integer field should die a quick death, and it appears to be doing that. I THOUGHT I was getting the key field for the selected record. Not happening though.

I don't think spreadsheets work as relational
databases?

Agreed. Spreadsheets don't have record keys, so no relation is possible. They can be used as read-only data sources in LO, though, I believe. Haven't tried this yet.

One of the 'obvious' 'easy answers' (and therefore most commonly
missed) is if the relationship is not defined in Base.

Well, it's not defined in Access either until done explicitly, and that is certainly possible also in Base. Doing this doesn't affect the problem at all, though.

The more I think about it, the more I become convinced that Frieder nailed it. I have to test this, but I think what's happening is that the list box selection I make simply produces the contents of the selected record. That shows up briefly in the text box, but cannot go from there to the record field underlying it, as THAT is an interger (to hold a key field's contents), and the list box selection is a text string.

OK...if so, then I need a macro to write the key of the selected record into the appropriate record field of my main table. oh, I'm not looking forward to this...I don't even know where to go to learn about LO Basic's object model, nor do I know where the language reference is. But if it's the only way then...

I'm afraid there NO documentation anywhere on this.

Thanks for your thoughts!

(and I'm still going to show up on the Base documentation list, probably tomorrow)

t.

Excellent idea. But I wasn't sure this wouldn't be asking too much. Can do easily, though.

Need to investigate some of the rest of your ideas first, though. Will put the file up if I get stuck

Thanks!

Tom Cloyd tc@tomcloyd.com (435) 272-3332

Hi Tom,

Um. Where in the world is this documented. I don't quite get it - and
example would help, and the only one I've found looks inappropriate. It
uses a list box simply to fill a field, not to insert a key which points
to the field, and THAT's what I want. NOT to do this would de-normalize
the database, would it not? So why would I EVER do that?

You really need to browse through the openoffice.org forums in the Base
section. Your problem has almost certainly been expressed there in the past.

http://www.oooforum.org/

and

http://user.services.openoffice.org/en/forum/

Alex

Totally in agreement. I got up this morning feeling a bit guilty. I finished an 87 hour work week yesterday, and wasn't exactly at my best last night. Searching the forums is a most sensible thing to do - I'm on it.

Thanks.

t.

________________________________
From: Tom Cloyd <tc@tomcloyd.com>
To: users@global.libreoffice.org
Sent: Mon, 20 June, 2011 17:02:46
Subject: Re: [libreoffice-users] Re: List box not updating field with bound
value

On 06/20/2011 02:22 AM, Alexander Thurgood wrote:

Le 20/06/11 09:05, Tom Cloyd a écrit :

Hi Tom,

Um. Where in the world is this documented. I don't quite get it - and
example would help, and the only one I've found looks inappropriate. It
uses a list box simply to fill a field, not to insert a key which points
to the field, and THAT's what I want. NOT to do this would de-normalize
the database, would it not? So why would I EVER do that?

You really need to browse through the openoffice.org forums in the Base
section. Your problem has almost certainly been expressed there in the past.

http://www.oooforum.org/

and

http://user.services.openoffice.org/en/forum/

Alex

Totally in agreement. I got up this morning feeling a bit guilty. I
finished an 87 hour work week yesterday, and wasn't exactly at my best
last night. Searching the forums is a most sensible thing to do - I'm on it.

Thanks.

t.

Hi :slight_smile:
Don't worry, we all blow our stack occasionally. My keyboard suddenly stopped
working in mid-sentence and then my internet went down for a day so i wasn't
around respond. Sorry about that!

If you were looking for setting up relationships between tables then hopefully
that is in the "Getting Started with Base" guide, page 14 i think
http://www.libreoffice.org/get-help/documentation/

People are currently working on the Base Documentation but could use more help.
Only Writer and Calc have been fully completed so far but the old OpenOffice
guides should be useful as not much has really changed in Base.

As i understand it the list boxes can use a proper table which could be quite
tiny and gives you greater control and more finesse. The list-box would show
the data field NOT the id/key and might allow new entries if set-up right.

Regards from
Tom :slight_smile:

Hi :slight_smile:
Sorry i only just got down this far in my emails list. Please ignore my last
post in this thread
Regards from
Tom :slight_smile:

Arrrgh! What a long, sad march through the wilderness this has been. Following what seemed like a most reasonable suggestion (which I wouldn't have needed had I been less exhausted when I posted originally), I went searching in the OO forum archive (well, using Google, to be truthful, which isn't quite the best way, but I'm in a hurry) to find out why my list boxes weren't working, and what I could do to fix them.

In short, there's a lot of smoke out there, but damn little fire. Theorists abound, and some folks definitely found the long way round the mountain (and lost ME in the process). I just wanted to build a fire and cook some supper. More particularly, I wanted to place a number in an integer field in my main table which could be linked to a key in another table so that a data field in the record with the matching key can be made to appear in the main record, using relational database magic. Maybe one can do all sorts of other things with list boxes, but I'm not interested. I'm just trying to build a form that uses a table relation locate the value I want for my main table record, and put that value's key into a field in the main record. This is a basic, routine thing one does with relational databases. Because I do it somewhat less than daily, I need written instructions to keep me from shooting my foot.

Here's where you won't find out how to do it - the " Combo Box/List Box Wizard" article in the LO help file. I read that thing 3 times, and I've used list boxes in MS Access for years, but I still don't know what they're talking about. For technical writing real people can use, this one gets a "D'. My despair increased perceptibly after my encounter with this disastrous article.

I'll skip additional recounting of the misery I encountered trying to find some straightforward instructions about how to do what I wanted to do. Instead, I'll provide some:

GOAL: Using a form which has text boxes linked to fields in your main table, you want to be able to select values for some of the fields, using a drop down list box. The value selected will be placed in the main table indirectly, using a reference to another table which contains the possibilities available for the main table field. This reference is, of course, a record key field. Using this indirect reference, we keep the database "normal", which helps to minimize data entry error (which makes data retrieval harder, when it occurs).

DO THIS:

1. CREATE VIEWS. You will using a main table and one or more secondary tables, with the latter providing the list contents for the list box controls you'll be setting up in your main table. Since table field names aren't always human-friendly, and in any case may need to be changed in the future, create a view for each table, such that those fields which need them have "aliases" to make field labels more human-friendly (understandable). Since you're going to use view, and not tables, should you need to change these labels in the future, you need do it only once - in the view, rather than in each table in which the field appears.

2. CREATE A BASIC FORM. Use the form wizard to quickly make a form containing the fields from your main table which you care about. Use any of the templates you wish, as long as the result is that the desired record fields for a single record appear on the form. (This is the quick way to get things going.)

3. LOCATE THE FIELDS OF INTEREST. These would be those that at this point are text boxes linked to fields, but which you wish to be list boxes linked to main table fields. With EACH of them, execute the remaining steps in this list:

4. REMOVE THE TEXT BOX (ONLY). Use Ctrl+L-click to select the box, apart from its label, which you're going to keep. Delete the selected box.

5. CHECK TO SEE THAT "AUTOMATIC WIZARD" IS ON. (OK, I'm only approximating its name, 'cause I don't really know what it is.) You should have the "Form Controls" tool bar visible on the left side of your form designer window. (If it isn't, activate it through View > Toolbars.) Second icon from the bottom, you'll see a magic wand (I promised you relational database magic, right?), or maybe it's just a road flare. In any case, it should be depressed. When it is, and you create a list box, you'll get some wonderful help, and all your misery will cease. Believe me, I know.

6. CREATE A LIST BOX. Seven icons up from the bottom, on the same toolbar, is the list box icon. Click it, then move your mouse pointer into some blank area of your form. Click and move the mouse diagonally down, to make a box. Don't worry about it's shape, as it's not yet important. The wizard will appear, and THAT is. Using it, you will quickly and painless do 3 critical things:
     a. Pick the table that will provide list box contents.
     b. Pick the field to appear in the list box.
     c. Link [a] the field in the main record that is to hold the key of the record in the list box source table with [b] that key in the list box source table. (Obviously this is a critical step, so get it right. Mess up and you get to start over from the beginning.)

7. RESIZE, AND REPOSITION, THE LIST BOX. You probably want it the same height as the other, non-list box fields, and wide enough to hold whatever you will be putting into it. You can then move it into the place formerly occupied by the text box it replaces.

8. TUNE UP THE LIST BOX. Click on the box to get Properties dialog. Do this:
     a. Change "Dropdown" to yes. (This way, you'll actually get to SEE your list. So, why isn't this set by default? I have no idea.)
     b. Change "Line count" to equal the number of items from your source table which you want displayed in your list box.
     c. If you want to have the list box look like the text boxes on your form, change the "Background Color" to "10% gray", and "Border" to "3D look".

Before closing the properties dialog, click the Data tab, and look at what you did NOT have to do - all this is set up for you by the Wizard, which (unlike me) is likely to get it right. Look at the Events tab too. See? No macros either. Relational database magic (well, Base magic...). You're still as informed as you ever were about macro programming after this exercise, and have saved a ton of time. If you got the results I got, your list box just works. (OK, close the property dialog now).

So, my journey into Base continues. It seems rugged, feature rich, and just works, if you can figure things out. I really do like it, I'm very very grateful to have it access to it.

Yeah...we need to write some more documentation. I've formally begun my involvement with that issue. Looks like fun, and of course, a lot of work.

Hope this is useful. I know I'll personally be using it in the future.

Tom Cloyd, MS MA
tc@tomcloyd.com
(435) 272-3332
St. George/Cedar City, Utah

Hi :slight_smile:
So, you have managed to solve the problem and got it all working? I think the
word is "triumphal" rather than "sad"?

Regards and apols from
Tom :slight_smile:

You are, of course, entirely correct!

t.