Finding the key from TDBLookupComboBox Selection lazarus / 16-Databases ---------------------------------------------------------------------- jack · 2012-02-04 17:09 I have been digging for several hours trying to understand how I might retrieve the key from the field selected in a TDBLookupComboBox. I have the field data from the caption but cannot figure out how to get the key to that field. If anyone could help, perhaps with an example?? ---------------------------------------------------------------------- LuizAmérico · 2012-02-04 17:17 TDBLookupComboBox.KeyValue ---------------------------------------------------------------------- jack · 2012-02-04 21:19 Thank You, I looked  and looked and did not see. ---------------------------------------------------------------------- jack · 2012-02-05 03:29 I was having fits with this until I realized that the KeyValue was not always being returned, sometimes it is null which throws an exception.  This turns out to be because I had not identified the primary key field in the TSQLQuery.  I did not because I never intended to write to the database.  Apparently the TDBLookuoComboBox somehow needs to know the primary key also. To fix this I Double click on the TSQLQuery and adding all the fields in the popup box (click the plus sign - hint: if the plus sign does not produce a list of fields then the query is inactive).  Then select the field that is the table primaty key and in the properties window, set the providerFlags[pfinkey] to true. This established the primary key and fixed my problem with nulls coming back as the KeyValue. Thanks again to all who have been answering my questions along the way!!!