Delphi Combo Box and MSAccess
Posted on 2006-07-08
I am currently converting the forms from an MS Access database to Delphi. For simplicity sake, I'll only be using two tables:
The Titles table has two fields and three records:
The Contacts table has four fields and two records:
ContactID Title FirstName LastName
1 1 John Smith
2 3 Jane William
Ive added an ATOTable control to my form and linked it to the Contacts table. I've also added a combo box for the titles and linked this up using the field editor.
I then populate the combo box using the following code:
Control_Data : TADOTable;
Control_Data := TADOTable.Create(frmMain);
with Control_Data as TADOTable do
Name := 'adoData';
ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Delphi\Data.mdb;Persist Security Info=False';
TableName := 'Titles';
while not Control_Data.EOF do
Now obviously, when the form is loaded the combo box isn't sitting on the correct entry as I store the titles by their ID instead of their String value.
Is there a way that I can link the Title's ID number stored in the Contact table with the TitleID for when I populate the combo box so that the correct entry is displayed when switching between records?
I've spent abit of time looking around for a solution for this without any luck and I feel that it's something simple that I must be missing. If it isn't as easy as I thought then I am willing to increase the points.
Thanks in advance,