Display Values During Insert

indigo

Member²
I have the following SQL:

select visits.*, visits.rowid, accounts.name
from vists,accounts
where visits.AccountNo = accounts.AccountNo

When the DBText for accounts.name is displayed for existing records, everything is ok.

When I insert a record, the DBText field is blank. What method can I use to display the value of accounts.Name after the user exits the visits.AccountNo DBEdit so that the user can see the name of the account they entered? The accounts file contains millions of records.

Thanks
 
See the DeptEmp demo for an example. In this demo the name of the manager of the employee is displayed after entering a manager id. The query is a similar join as the one you mentioned.

Note that the FieldKind of the Account.Name field must be set to fkInternalCalc.
 
Marco:

I think I followed the example, but it does not work properly.

The key changes I made are:

I double clicked my TOracleDataSet and made everything persistent fields. I changed the type on my TaxpayerName field to fkCalculated, changed its Origin to Taxpayers.TaxpayerName, and changed ReadOnly to True.

I added an onValidate event to the AccountNo field. Here is the code:

if taVisitsAccountNo.IsNull then
taVisits.TaxpayerName.Clear
else with TaxpayerNameQuery do
begin
SetVariable('AccountNo'),taVisitsAccountNo.Value);
Execute;
if Eof then
taVisitsTaxpayerName.Clear
else
begin
taVisitsTaxpayerName.Value := Field('TaxpayerName');
if taVisitsCollectorNo.IsNull then
taVisitsCollectorNo.Value := Field('CollectorNo');
end;

When I insert a record, the correct value is displayed in the TDBText for TaxpayerName. But for existing records, the name is not displayed in the TDBText or in TDBGrids.

Please help.

Thanks
 
You need to set FieldKind to fkInternalCalc.

A FieldKind of fkCalculated assumes that you have an OnCalcFields event, which does not apply here.
 
That worked fine. I only need this when there are too many records in the lookup database to use a TDBLookupComboBox.

I am currently converting one of my large applications to Oracle. Is there no other way to accomplish this which does not require dropping queries, etc.?
 
Back
Top