Delphi - Database filter


I have a customer form that grabs information from a paradox table called "customer".  This form also has a data grid that lists all the items that the customer has purchased, which is stored in another paradox tabled called "sales".

What I want to do is filter the data grid by customer name, so that when the user navigates through each customer, only their sale information is displayed in the datagrid.

The data grid is linked to a different table object on the form.  I've tried to apply a filter to the datagrid already, using:

SalesTable.Filter := '[Customer Name] = ' + '[' + CustomerTable.FieldByName('Customer Name').Value + ']';

But this results in an error.

It feels like I'm missing something very minor.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I would think that your filter need to be like follows...

SalesTable.Filter := 'Customer Name = ' + '''' + CustomerTable.FieldByName('Customer Name').Value + '''' ;
Assuming Customer name is a string.

I also would have thought that you can not have a space in the field name, is it really Customer_Name maybe....

You could also set a master detail relationship between the two tables, this is probably a better way to do it.
SebastionAuthor Commented:
There is a space, in the field "Customer Name" in the paradox database.  Personally, I'd probably have put CustomerName, but I'm actually building off a previous setup here.

The field is indeed a string, but if I take away the square brackets [], then the compiler doesn't interpret the full field name.

For example, in the above code you've written, the following error results:

SalesTable: Field 'Customer' not found.  Process Stopped.  Use Step or Run to continue.

However, if I put square brackets around the words "Customer Name", the compiler can now interpret the entire string, and finds the field fine.

I could try a master detail relationship, could you give me the gist of what I would have to do to accomplish this?
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Sorry about that, sort of assumed that Customer Name was incorrect.
For the Master Detail.....
On the Sales table you need to set the MasterSource property to a datasource component that points to the Customer Table.
Then set the Masterfields property on the Sales table to the master field in the Customer table i.e Customer Name.
The Sales table also has to be indexed to the Customer Name Field.
The sales table will then only show the records for the Customer Name that match the master table.

I hope that makes sense....
How is the weather in Queensland, it is freezing in Victoria. (Unusual...)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SebastionAuthor Commented:
Hmm, from the looks of things it's going to use the primary key of the sales table, which is SalesID.  This actually cannot be linked to anything in the Customer table, since it's only used to uniquely identify each individual sales record.

Since the link appears to require a primary key on the SalesTable part, then I wouldn't be able to simply make the "Customer Name" field in the sales table a primary key, as it's not unique (A Customer could have many different sales).

Any thoughts?

P.S, it's actually quite warm up here in Queensland, though it's been threatening to storm for the last couple of days.
The index does not have to be unique. Can be a "normal index"
SebastionAuthor Commented:
According to what I've got, the only option under "available indexes" is "primary".
You would need to create an index on the Customer Name field.
I dont think even using the indexfieldnames property is an option, because I think paradox still requires it to be indexed. (Havent used paradox for a while)
SebastionAuthor Commented:
Yep, you're right.  I set up the customer name field as an index through the paradox database management program and it's now an option in the master-detail relationship.  Things look to be working alright, with the few meager test entries that I've entered in.

Thanks for the help
Glad I could help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.