| View previous topic :: View next topic |
| Author |
Message |
chrissekely General User

Joined: 02 Jun 2009 Posts: 6
|
Posted: Tue Jun 02, 2009 1:37 am Post subject: Using a list-box to limit entries in a foreign key field |
|
|
I am still using Open Office version 3.0.1 (I plan to update it soon) on Windows Vista. Just providing standard info here, though it probably won't help much.
This is our problem:
We are presently developing the data entry forms for three of the tables in a larger relational database. We have a table of drivers, a table of customers, and a table of persons. Fields unique to a driver (such as their hire date and company assigned driver number) are stored in 'drivers'. Similarly, fields unique to customers are stored in 'customers'. All common data (name, address, and such) is stored in 'persons'. In fact, 'persons' then links to 'phone_numbers', allowing each individual to have more than one phone number. With this structure, one person could be both a driver and a customer. This does occur. Storing this info this way is also more space efficient. The problem we've encountered is that two or more different records in the 'drivers' (or 'customers') table may refer to the same person. I do not believe Base provides a way to enforce a one to one relationship, effectively limiting a foreign key field to only unique entries (no duplicates).
We are approaching a solution to this problem, but are encountering some trouble. We are attempting to prevent this problem on the form level, by providing a list or combo box that limits the possible options that a user may choose. The list of options the user may choose would be populated from a query which compares the contents of two fields. 'ID' is the primary key field of 'persons' and 'Person_ID' is the foreign key field in 'Drivers' that links to 'ID' in 'Persons'. Using MySQL, our query looks like this:
| Code: | SELECT CONCAT( `Last_Name`, ', ', `First_Name` ) AS `Name`, 'ID' FROM `taxi_unstable`.`persons` WHERE NOT `ID` IN ( SELECT `Person_ID` FROM `drivers` WHERE `Person_ID` IS NOT NULL ) ORDER BY `Name` ASC
|
If you have followed me so far, hopefully you can catch this next bit, because this is the crux of our problem right now.
Using a list-box is ideal, because it allows the user to to select the ID to store by choosing someone's name from a list. The IDs themselves would be meaningless to the average user. The problem with using a list box is hard to explain, but let me try. Every time a name/ID is selected for a particular record, the query eliminates that name from the list, ensuring that that name is not selected twice. However, list boxes do not allow any entries that are not in the list. So, as the list changes, any selections that had previously been made from that list are made Null because those items are no longer in the list. Using a combo box would solve this particular issue, but only if a combo-box could designate a different bound field. With a combo box, one cannot display one thing and store something else.
I hope some of you have had the patience to read all of this. I feel I've already written a small book. I'll stop here.
I would welcome any comments or suggestions. Thank you. |
|
| Back to top |
|
 |
iron-hands General User

Joined: 06 Jan 2009 Posts: 13
|
Posted: Tue Jun 02, 2009 5:26 am Post subject: |
|
|
| the problem, if i'm understanding correctly, is that you're unable to keep previously selected values when the listbox is changed? If that is the case, can you not, in your "on changed" event, store the value in a temp variable, refresh the listbox, then have it reselect(or add the item to the box if it doesn't exist)? |
|
| Back to top |
|
 |
chrissekely General User

Joined: 02 Jun 2009 Posts: 6
|
Posted: Sun Jun 07, 2009 10:11 pm Post subject: |
|
|
| Thank you. However, regarding a lot of this, we still feel like novices. Macros, VBA, Php, and the like are still a bit beyond the sort of thing we are willing to tackle at this point. I am wondering if there would be a solution that would only involve SQL and the OO Base interface. |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Mon Jun 08, 2009 12:20 am Post subject: |
|
|
Hello
If you want avoid macros then you have to understand the possibilities of the forms. Try to use the forms as a filter.
This link can maybe have information what can help you. I knew it use some macros but they are easy. But when you want avoid macros then you must use better the forms.
Romke |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|