Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBComboLookup usage

Status
Not open for further replies.

Oppenhiemer

Programmer
Jun 28, 2001
315
GB
Hi -

This is a lame question I know but here goes..

I have a form based on an Orders table. I have a field on the orders table called "CustCode". I would like to have a DBComboBox lookup component bound to the "CustCode" field on the orders table, to allow users to select a customer code. The ListSource for the DBLookupComboBox is the customers table.

Now I have tried several variations on ListSource,ListField,KeyField,DataSource and Datafield. And I cannot get it to function as one would expect.

If I link the various properties as I think they should be - it allows me to select a value from the list, it stores the value in the correct field - but will not display the selected item (the ComboBox looks blank.)

If I remove the Datasource/Datafield properties (so its un-bound) it functions as expected (expect for the obvios problem that it is no longer bound to any datasource!)

I have probably not explained this very well, so here is a link tha may shed more light on the problem ~:


I seem to remember having problems with these controls in the past (but its been some years now since I have used Delphi - so have forgotten all about it.)

Anyway, any help woul dbe much appreciated.

Cheers..
Opp.
 
There are two FAQ's dealing with look-up fields in this forum:

faq102-1213
How to use a look up field in a DBGrid


and
FAQ102-1212

Regards
Steven van Els
SAvanEls@cq-link.sr
 
Yes - thanks Steven, but the first deals with DBGrids and the second example uses 2 different fields for the Keyfield and ListField Properties:


properties: DataSource = DataSource1 (main table)
DataField = Empno
the lookup part
ListSource = DataSource2 (look up table)
KeyField = empno (this is the link to main table, here are only elements from the main table)
ListField = LastName (What will be displayed in the combobox, the elements of the Lookup table)


So unfortunately, this does not help. In my case - I need to make the KeyField and the ListField the same field (I want the list to display the CustNo and for the CustNo to be the value thats is stored in the Datafield.)

If I do this, it does not operate as expected.

Any further suggestions would be much appreciated.

Cheers..
Opp.

 
Just tried creating a Lookup field to see if that could help. Ended up reading (or tried to) the help file relating to lookup fields.

Here is a extract from the help file "explanation" :

When a field component is a lookup field, the Value of the field component is the value of the LookupResultField in the LookupDataSet. The record in the LookupDataSet that contains the correct value is found by matching the LookupKeyFields in the LookupDataSet with the current values of the KeyFields in the DataSet.


Lol - Of course that makes eveything much clearer.


 
Put the listfield to custno Steven van Els
SAvanEls@cq-link.sr
 
Im not sure what Custno refers to Steven - but here is an example of the current setup.

I have a table called "orders". In this table - I have a field called Custcode. I have another table called Customers - where CustCode is the Key field in this table.

I would like to have a dropdown combo box that allows the user to select a customer from the list provided. So - I thought that I would set the DBLookupComboBox as follows :

DataSource : Orders
DataField : CustNo

ListSource : Customers
ListField : CustNo
KeyField : CustNo

But this does not work.

Opp.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top