0

Introduction

I have a form with a TComboBox that I want to populate with a field from a table in my database using a query. I also want the values in the field displayed in proper case, which can be achieved using Access’ StrConv function. Here’s my code:

with dmCallNote.qryCompany, SQL do
begin
  Clear;
  Text := 'SELECT StrConv(A_Company, 3) FROM tblAccounts';
  Open;
  while not Eof do
  begin
    cmbCompany.Items.Add(dmCallNotes.qryCompany['A_Company']);
    Next;
  end;
end;

The Problem

When compiling the line cmdCompany.Items.Add … I receive the error message:

“qryCompany: Field 'A_Company' not found.”

Why am I getting this error? When I run the query with a TDBGrid it executes successfully.

1 Answers1

2

Change this: Text := 'SELECT StrConv(A_Company, 3) FROM tblAccounts';

to this: Text := 'SELECT StrConv(A_Company, 3) AS A_Company FROM tblAccounts';

Your field had no name/alias.

Nick
  • 7,103
  • 2
  • 21
  • 43