Subject Re: [IBO] Problems with EOF
Author Lucas Franzen
Hi,

see remarks below

> procedure tform1.closeCorrespondence;
> begin
> qryFollowUpEmails.FetchAll;
> qryFollowUpEmails.first;
> qryFollowUpEmails.requestlive:=true;

first fetching all, then going to first then setting request live to
true is nonsense.
If you really change the setting of RequestLive you have to reopen your
query since it will tell the server: "Hey, it might happen that I'm
going to send you changed data"


> qryFollowUpEmails.open;

Now you open it.
Sorry but it is already open, otherwise you couldn't have gone to the
first record.

> qryFollowUpEmails. edit;

Now you edit it, okay, but in the nexct line you start a loop.
So edit is just called for the first record!

> while not qryFollowUpEmails.Eof do
> begin
> with qryFollowUpEmails do
> begin
> fieldbyname('correspondencedate').value:=now();
> Fieldbyname('status').AsString:='closed';

assigning new values here will set the query back to edit mode again
(which you just call explicitely once for the first record, see above)

> end;
> next;

where does this next belong to?

> end;

> qryFollowUpEmails.post;

and you post once. Which is the same nonsense as editing once.

> end;

Maybe your code should look like:

procedure tform1.closeCorrespondence;
begin
with qryFollowUpEmails do
begin
try
First;
while not EOF do
begin
Edit;
Fieldbyname('correspondencedate').value:=now();
Fieldbyname('status').AsString:='closed';
POST;
end;
NEXT;
except
if State in [dssEdit] then Cancel;
end
CLOSE;
end;
end;

Luc.