Board index » delphi » Novice Query question

Novice Query question

hi all,

I'm having problems with Tquerry about searching an
existing value in a Query or table, it's simple, I want to
know if a CustIDnumber already exist.
is there a function or proc in TQuerry that can do
that?
I was using some code like this:

QQuery.first;
While not QQuery.eof do
        if QQueryCustID.value = EditCust.text then
       begin
           ShowMessage('ID Already exist!');
           QQuery.last;
       end else QQuery.next;

But when this loop finishes I cant get the focus back
to the Edit control I left before, can I search that without
leaving the current record?    
Suggestions are wellcome...
Is the TQuery.Lookup() function related with?

 

Re:Novice Query question


Hi Manuel!
I supose you have a primary index on CustIDnumber.
I've done a lot of research on this problem and I couldn't find any
other solution that to put a second TTable-object on the form. This
table object I set IndexName to Primary Index and then I use this
object to check for existens of ID.
The code (whick I put in OnChange-event if using a TDBGrid or in
OnExit-event if using TDBEdit) then looks like this:
    if SearchTable.FindKey([SearchTableCUSTID.AsString]) then  { or
.AsNumber if it's a numeric column }
    begin
      ShowMessage('ID Already exist!');
      MessageBeep(MB_ICONSTOP);
      Abort;
    end;

Hope this will get you on the right track.
/ Ingemar Magnusson, Oxel?sund, Sweden

Manuel Jacquez skrev i meddelandet ...

Quote
>I'm having problems with Tquerry about searching an
>existing value in a Query or table, it's simple, I want to
>know if a CustIDnumber already exist.
>is there a function or proc in TQuerry that can do
>that?
>I was using some code like this:
>QQuery.first;
>While not QQuery.eof do
> if QQueryCustID.value = EditCust.text then
>       begin
>    ShowMessage('ID Already exist!');
>    QQuery.last;
>       end else QQuery.next;
>But when this loop finishes I cant get the focus back
>to the Edit control I left before, can I search that without
>leaving the current record?
>Suggestions are wellcome...
>Is the TQuery.Lookup() function related with?

Other Threads