Below is my code where I am trying to delete records from a dbf where the date in each record is not today please can some point out where I am going wrong as when I run this, it only appears to be deleting some of the records and each time I click the button that runs this, it does some more BUT even deletes todays record!
if dbf1.active = true then
begin
// dbf1.Filtered:=true;
dbf1.IndexName:='';
prev := 1;
dbf1.Filtered:=true;
dbf1.DisableControls;
if dbf1.ExactRecordCount>0 then
begin
dbf1.Filtered:=false;
dbf1.Active:=false;
dbf1.Active:=true;
dbf1.First;
while not dbf1.EOF do
begin
if DateOf(dbf1.FieldByName('dateon').AsDateTime)<DateOf(now) then
dbf1.Delete;
dbf1.Next;
end;
dbf1.TryExclusive;
dbf1.PackTable;
dbf1.EndExclusive;
dbf1.Filtered:=false;
dbf1.Active:=false;
dbf1.Active:=true;
dbf1.EnableControls;
dbf1.first;
prev := 0;
end;
the variable prev is set to trigger the required filter in the OnFilterRecord procedure :
if prev = 1 then
begin
accept := (DateOf(Dataset.FieldByName('dateon').AsDateTime)<DateOf(now));
end;
Any Ideas please, I thought this would work but it appears not to
Thanks
TimCS