How to return Selected Row information from DBGrid back to calling form when DBGrid filtered with SQL?

Hi All,

I have a search form which allows a "Select *" type SQL statement to be performed on a table when first opened.

The intent is for the user to be able to filter the SQL statement further, and then to return the selected item back to the calling form, in order to be able to update that form, or alternatively to review details (based upon the selected item).

So far so good - I have the filter and the search form going well

The problem that I have is when I want to select that record and review it in the calling form, or use the information to update the calling form.

I've tried using RecNo, but that will only give me the correct record associated with the unfiltered search.

If I filter the search, RecNo could well be for example, the ninth record overall, but only the second record when filtered. The result returned to the form is the second record overall.

How can I get this item to perform for me, so that as per the example: the second filtered record on the DBGrid is returned as the correct ninth record overall to the calling form?

thanks in Advance
Who is Participating?
Ferruccio AccalaiConnect With a Mentor Senior developer, analyst and customer assistance Commented:
use simply a Locate....

I mean to apply a locate to the overall with the fields values from the search

For example your overall structure is

Id   Name   Age

1    Alan     10
2   Jhon      12
3   Mark      13

and the search result is 2 jhon 12

you can pass a Overall.Locate('ID;NAME;AGE',

This will locate 2^ record on Overall
geobulConnect With a Mentor Commented:

It seems that you are having two query objects - one on the main form and one on the search form. And you want to pass a selected record number (some info) to the main form in order to main form's query to go to that record.

If that is correct then perhaps you could use one query object on the main form only, use the same query in the select form and after 'filtering', selecting a record and closing the select form your main form's query will be positioned on the right record automatically (the query will remain filtered, of course, but that shouldn't be a problem because your users can always open the search form again and remove all current filters).

Regards, Geo
calinutzConnect With a Mentor Commented:
On the OnKeyUp event of the Searching form place this code:

If ((key=13) and (ssCTRL in Shift)) then

If key=27 then Close;

// this code returns from the search form closing it and if you press CTRL+Enter on a record then It sends the value from the chosen record to the Initial Form.

// I hope this is what you needed
My recommendation : split the points.
gunnadothatAuthor Commented:
Hi All,

sorry about not finalising this earlier - Uni had finished for the year and I simply forgot to complete the feedback.
Please accept my apologies.

I've split the points according to the use that I made of the answers - all were good, but I used Ferruccio68's answer as the basis for the filter, and the other responses were great to put it all into perspective.

Once again, i apologise for not doing this sooner, and thanks Dan for the prompt to complete this item - much appreciated to all.


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.

All Courses

From novice to tech pro — start learning today.