Board index » delphi » 'Record not found' with table.Locate

'Record not found' with table.Locate

Hi,

does someone know under which condition table.locate method produces
'Record not found' error ?!

Everything seems OK (locate shuold return TRUE)

TIA, Bojan

 

Re:'Record not found' with table.Locate


Bojan,

Quote
> does someone know under which condition table.locate method produces
> 'Record not found' error ?!

Locate returns false if a record is not found.  If what you're after is
that you want to display 'Record not found' in a message dialog try
something like:

if not CustTable.Locate('CustNo',  CustNo.Text, []) then
  MessageDlg('Record not found', mtError, [mbOk], 0);

The above is looking for an exact match in the CustNo field.  If you're
looking for the closest math then do:

if not CustTable.Locate('CustNo',  CustNo.Text, [loPartialKey]) then

Hope this helps.

Robert Schiller

Re:'Record not found' with table.Locate


Quote
Robert Schiller wrote:

> Bojan,

> > does someone know under which condition table.locate method produces
> > 'Record not found' error ?!

> Locate returns false if a record is not found.  If what you're after is
> that you want to display 'Record not found' in a message dialog try
> something like:

> if not CustTable.Locate('CustNo',  CustNo.Text, []) then
>   MessageDlg('Record not found', mtError, [mbOk], 0);

Robert, that's NOT a problem. I read on-line help about locate method
and *use* it in several applications with success.

The problem is that with a simple statment:

 if table2.locate('Test', table1.fieldByName('Id').value, []) then ...

I get a *EDatabaseError* 'Record not found' !!

Is the problem connected with field types?? 'Test' is longint and 'Id'
is autoinc. field...

TIA, Bojan

Re:'Record not found' with table.Locate


Quote
Bojan Leskosek wrote in message <36173BC6.7...@guest.arnes.si>...
>Robert, that's NOT a problem. I read on-line help about locate method
>and *use* it in several applications with success.

>The problem is that with a simple statment:

> if table2.locate('Test', table1.fieldByName('Id').value, []) then ...

>I get a *EDatabaseError* 'Record not found' !!

>Is the problem connected with field types?? 'Test' is longint and 'Id'
>is autoinc. field...

You normally get that when there are no records in the database. You also
sometimes get an "at beginning of table" error message. It can also happen
when you spell the names of the fields incorrectly.

Regards
Darren Lyon
Soft-Co Australia

Re:'Record not found' with table.Locate


Quote
HardTech Computers wrote:

> Bojan Leskosek wrote in message <36173BC6.7...@guest.arnes.si>...

> >Robert, that's NOT a problem. I read on-line help about locate method
> >and *use* it in several applications with success.

> >The problem is that with a simple statment:

> > if table2.locate('Test', table1.fieldByName('Id').value, []) then ...

> >I get a *EDatabaseError* 'Record not found' !!

> >Is the problem connected with field types?? 'Test' is longint and 'Id'
> >is autoinc. field...

> You normally get that when there are no records in the database. You also
> sometimes get an "at beginning of table" error message. It can also happen
> when you spell the names of the fields incorrectly.

Darren,

I check all conditions you mention - none of them is true.

Any other idea?

TIA, Bojan

Re:'Record not found' with table.Locate


My guess would be that table1 is causing the problem.  Have you tried
splitting the statement in two lines?

HTH

Jan

On Sun, 04 Oct 1998 10:11:34 +0100, Bojan Leskosek

Quote
<bojan.lesko...@guest.arnes.si> wrote:
>The problem is that with a simple statment:

> if table2.locate('Test', table1.fieldByName('Id').value, []) then ...

>I get a *EDatabaseError* 'Record not found' !!

>Is the problem connected with field types?? 'Test' is longint and 'Id'
>is autoinc. field...

>TIA, Bojan

Re:'Record not found' with table.Locate


Quote
Jan Sprengers wrote:

> My guess would be that table1 is causing the problem.  Have you tried
> splitting the statement in two lines?

> HTH

> Jan

I do! Table1 is OK - returned value is not null (i.e. positive
ineteger), if this is, what you mean?

Bojan

Quote

> On Sun, 04 Oct 1998 10:11:34 +0100, Bojan Leskosek
> <bojan.lesko...@guest.arnes.si> wrote:

> >The problem is that with a simple statment:

> > if table2.locate('Test', table1.fieldByName('Id').value, []) then ...

> >I get a *EDatabaseError* 'Record not found' !!

> >Is the problem connected with field types?? 'Test' is longint and 'Id'
> >is autoinc. field...

> >TIA, Bojan

Re:'Record not found' with table.Locate


Could the error be refering to table1?
For debugging try breaking your code into 2 lines

ID := table1.fieldByName('Id').asInteger;
if table2.locate('Test', ID, []) then ...

Quote
Jan Sprengers wrote in message <3619c39c.3338...@forums.inprise.com>...
>My guess would be that table1 is causing the problem.  Have you tried
>splitting the statement in two lines?

>HTH

>Jan

>On Sun, 04 Oct 1998 10:11:34 +0100, Bojan Leskosek
><bojan.lesko...@guest.arnes.si> wrote:

>>The problem is that with a simple statment:

>> if table2.locate('Test', table1.fieldByName('Id').value, []) then ...

>>I get a *EDatabaseError* 'Record not found' !!

>>Is the problem connected with field types?? 'Test' is longint and 'Id'
>>is autoinc. field...

>>TIA, Bojan

Other Threads