Subject Re: [IBO] IB_LookupCombo + OnChange Event
Author Helen Borrie
At 03:28 AM 24/06/2006, Andrei wrote:
>Hello,
>
>I'm having problem on using OnChange of IB_LookupCombo.
>
>I have the following scenario:
>
>Form: frmSales
>
>1 IB_LookupCombo to choose the customer.
>Several IB_Edits like Salesman, payment terms, delivery date, etc...
>
>When I choose any customer, I'd like to fill in the Salesman IB_Edit
>with the value that is stored in Customer Table. I need this, cause
>the salesman that is stored in customer table is just a sugestion.
>
>qrCustomerLookup
>Fields: ID, Name, SalesMan
>
>qrSales
>Fields: ID, Customer_ID, SalesMan
>
>So, in IB_lookupCombo onChange event, I have something like that:
>
>qrSales.FieldByName('SalesMan').asString :=
>qrCustomerLookup.FieldByName('SalesMan').asString;
>
>But, nothing is working, when I click on a customer at IB_LookupCombo,
>the value didn't appear, and SalesMan on Sales table is not filled.
>
>If I comment the code above, the value appear, but SalesMan is not
>filled, of course.
>
>As I verify by debuging, the OnChange is triggerd twice (!?), the
>first one, the cursor on qrCustomerLookup is OK, where I clicked and
>qrSales.Salesman is filled perfect, but the second one, the cursor is
>empty, and then qrSales.Salesman is filled with an empty string.
>
>What I'm doing wrong.
>
>Hope I was clear, my english is too bad...
>
>Win XP Pro + D2006 Pro + FB 1.5.2 + IBO 4.6B

Have you looked at the TI sheet about IBO controls? And the Help file?

You will find out that TIB_LookupCombo is a special control,
different from others, in that it is "double-data-aware". Like other
data-aware controls, it is linked to a field in the dataset that
wants to use it via a key; but it is also linked to its own lookup
dataset. In other words, it is keeping two independent datasets
linked to each other. (This is different to Master-detail, which
manages the subsets of one dataset in a dependency that has structural rules.)

The relationship between the LookupCombo and the master set's key is
referred to as a "Lookup-Keysource" relationship in IBO terms. The
lookup set provides the values in the lookupcombo control and the set
points to the Datasource of the master set via KeySource.

The Datasource property of the Lookup set is not involved in this relationship.

In the simple case (which your example is not) the primary key of the
lookup set points to the "polling field" in the KeySource by way of
KeyLinks. That is, you should have a field in your master set that
contains the PK of a record in a table that stores the ID and the
name of one Sales Manager in each record.

The information you provided is not sufficient to tell whether the ID
in your qCustomerLookup is unique to one and only Sales Manager. So
tell us more about your structure.

If, as I suspect, you have a denormalised structure here (you are
storing the Sales Manager name in both the Customer and the Sales
tables and you do not have a table that uniquely identifies a Sales
Manager by some ID), then the LookupCombo control won't work, because
the lookup set has no unique key. In that case, you will need to use
a TIB_ComboBox instead, which is not double-data-aware. You would
populate the ComboBox using a method that can extract the Sales
Manager names distinctly from the Customer table and provide them as
a list to the ComboBox.

Never use the OnChange event to get values to write. The OnChange
event fires every time the current row pointer is moved. It is not
an "OnModify" event.

Helen