[Solved] ListBox writing incorrect IDs

Discuss the database features
Post Reply
EdSmelly
Posts: 2
Joined: Sun Nov 19, 2017 12:35 am

[Solved] ListBox writing incorrect IDs

Post by EdSmelly »

I have a small form to help me keep track of my expenses. The Expenses table has a relationship to the Categories table via CategoryID.
On my form the Categories listbox correctly displays the Category names but always writes 0 to the Expenses table.
If I write an INSERT query to write the data directly then everything works as expected. This leads me to think that the ListBox isn't representing the data correctly.
I have ListBoxes for Vendor and PayType also and they are exhibiting the same behavior.
Is there any way of viewing the INSERT statement being generated by the form? How do I debug this?

Thanks,
Last edited by EdSmelly on Sun Nov 19, 2017 1:11 am, edited 1 time in total.
OpenOffice 4.1.4 on MacOS 10.13
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: ListBox writing incorrect IDs

Post by Villeroy »

Linked Field: CategoryID [the foreign key to be written]
Source Type: SQL [most flexible]
Source: SELECT "Name", "ID" FROM "Categories" ORDER BY "Name" ["Name" is the visible field, ID is the other table's primary key]
Bound Field: 1 [which is the second one, the visible one is 0]

Alternatively, save the SQL in a query
Source Type: Query
Source: query name
This is more handy if you need the same listbox in many forms.
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
EdSmelly
Posts: 2
Joined: Sun Nov 19, 2017 12:35 am

Re: ListBox writing incorrect IDs

Post by EdSmelly »

Villeroy wrote:Linked Field: CategoryID [the foreign key to be written]
Source Type: SQL [most flexible]
Source: SELECT "Name", "ID" FROM "Categories" ORDER BY "Name" ["Name" is the visible field, ID is the other table's primary key]
Bound Field: 1 [which is the second one, the visible one is 0]
Yup, that was it alright. I used the wizard to design the form and when I added the ListBox I told it that I wanted the Category ID and the Category name and the statement it chose was SELECT "Name", "Name" FROM "Categories"... Also I don't recall seeing any reference to the Bound Field in the docs.
Thank you.
OpenOffice 4.1.4 on MacOS 10.13
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [SOLVED] ListBox writing incorrect IDs

Post by Villeroy »

Forget the form wizard. It does not even cover 10% of the possibilities. This forum has plenty tutorials and examples about proper form design.
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