Solved

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

Posted on 2004-09-26
6
415 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:gunnadothat
6 Comments
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 130 total points
Comment Utility
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',
                                             VarArrayOf([search.fieldbybyname('id').AsInteger,
                                             search.fieldbybyname('Name').AsSTring,
                                             search.fieldbybyname('AGe').AsInteger]),[]);

This will locate 2^ record on Overall
0
 
LVL 17

Assisted Solution

by:geobul
geobul earned 70 total points
Comment Utility
Hi,

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
0
 
LVL 11

Assisted Solution

by:calinutz
calinutz earned 50 total points
Comment Utility
On the OnKeyUp event of the Searching form place this code:

begin
If ((key=13) and (ssCTRL in Shift)) then
begin
InitialForm.Edit1.Text:=DBGrid1.Fields[0].AsString;
InitialForm.Edit2.Text:=DBGrid1.Fields[1].AsString;

Close;
end;
If key=27 then Close;
end;

// 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
0
 
LVL 17

Expert Comment

by:geobul
Comment Utility
My recommendation : split the points.
0
 

Author Comment

by:gunnadothat
Comment Utility
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.

regards

GdoT
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now