I have a Master/Detail relationship of Cheques and the Invoices that the
cheques are paying. I want to walk the master and detail tables and for
each record in each table append a record to a history file. The code
follows:-
THE PROBLEM:
When I put the Hist table in append mode, the order of the IPayInvs table
changes half way through the walk and so some records are missed and others
are doubled up. If the Hist.Append block is commented out every record is
read in the correct order but if Hist.Append is attempted, the last record
is read and then the first and then each successive record however the
first record is missed.
I have tried various ways to overcome this like, no master/detail and
setting ranges based on the linking field and so forth..
Can anybody suggest where I am going wrong or perhaps a better way to
acvhieve the same result please?
Thanks Simon
procedure TForm1.UpdateMe;
var
CredCode : String;
ChequeDate : TDateTime;
ChequeNum : Integer;
begin
IPay.First;
repeat
begin
CredCode:=IPayCREDITOR.AsString;
ChequeDate:=IPayCHQDATE.AsDateTime;
ChequeNum:=IPayCHQNUM.AsInteger;
// Post the payed Invoices to Hist
UpdateTran(CredCode, ChequeDate, ChequeNum);
// Post the Cheque to Hist
Hist.Append;
Hist['CREDITOR']:=CredCode;
Hist['PAYDATE']:=ChequeDate;
Hist['CHQNUM']:=ChequeNum;
Hist['TRNTYPE']:='PAY';
Hist['SUMMARY']:=IPay['DESCRIPT'];
Hist['AMOUNT']:=IPay['TOTAL'];
Hist.Post;
IPay.Next;
end
until IPay.EOF;
end;
procedure TForm1.UpdateTran(CredCode: String; ChequeDate: TDateTime;
ChequeNum: Integer);
begin
// walk IPayInvs and append records to hist
IPayInvs.First;
repeat
begin
Hist.Append;
CR.Hist['CREDITOR']:=CredCode; // Give the invoice an owner
CR.Hist['PAYDATE']:=ChequeDate;
CR.Hist['CHQNUM']:=ChequeNum; // Give each entry in the hist file a chq
number
CR.Hist['TRNTYPE']:=CR.IPayInvs['TRNTYPE'];
CR.Hist['BATCH']:=CR.IPayInvs['BATCH'];
CR.Hist['BATCHPRINT']:=CR.IPayInvs['BATCHPRINT'];
CR.Hist['REFERENCE']:=CR.IPayInvs['REFERENCE'];
CR.Hist['SUMMARY']:=CR.IPayInvs['SUMMARY'];
CR.Hist['AMOUNT']:=CR.IPayInvs['AMOUNT'];
CR.Hist.Post;
IPayInvs.Next;
end
until IPayInvs.EOF;
end;