Problem with Insert Method, Please Help... 
Author Message
 Problem with Insert Method, Please Help...

Hi,

Using D4 C/S P3 & Paradox Tables.

I'm having a problem with records appearing in a table with no Job
Number or Index Number.

When the user clicks the "New Record" button. it seems that in some
cases the Insert Method is not being executed. This doesn't happen
often, but when it happens, the users cannot create any new records
because they get a Key Violation Error.

I haven't been able to track it down as yet and was wondering if
anyone else has seen the same problem.

The Insert Method basically opens the JobNumbers Table to read the
last job number used. It then increments the job number and saves it
back into the JobNumbers Table.

The Method then creates a new Job Number and Index Number using the
job number & year.
Here is the AfterInsert Method I'm using:

procedure TDM.AssessmentsAfterInsert(DataSet: TDataSet);
var
   JDRefNo, JDRefYear, newyear : word;
   Sender : TObject;
begin
     newyear := strtoint(FormatDateTime('yyyy', now));
{ Calculate New Job Number }
     JobNumbers.Open;
     if JobNumbers.FindKey([newyear]) then
     begin
          DM.JobNumbers.Edit;
          DM.JobNumbersJobNo.AsInteger := DM.JobNumbersJobNo.AsInteger
+ 1;
     end
     else
     begin
          DM.JobNumbers.Insert;
          DM.JobNumbersYear.AsInteger := newyear;
          DM.JobNumbersJobNo.AsInteger := 1;
     end;
     JDRefYear := DM.JobNumbersYear.AsInteger;
     JDRefNo := DM.JobNumbersJobNo.AsInteger;
     DM.JobNumbers.Post;
     JobNumbers.Close;

{ Save the new Job Number & Index to Assessments Table }
     DM.AssessmentsJobNoIndex.AsInteger := (JDRefYear * 100000) +
JDRefNo;
     DM.AssessmentsJDJobNo.ReadOnly := False; // Rev 1.13 RCP
     DM.AssessmentsJDJobNo.AsString :=
inttostr(JDRefNo)+'/'+inttostr(JDRefYear);
     DM.AssessmentsJDJobNo.ReadOnly := True;  // Rev 1.13 RCP
end;

I've had some debug code in this Method to try catch what was
happening and it then that I found out the Method wasn't being called.

Can anyone can shed some light on this?

Many Thanks,

Robbie...



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Transaction Methods in Interbase using Delphi 3.0 -Problems in commit-rollback methods

2. ObjectWindows - TPW 1.5 Insert Method

3. I need to insert some assembler. PLEASE HELP

4. Please help, can't insert records.

5. PLEASE HELP! SQL Insert key violation error

6. Problem with AfterInsert Method, help needed...

7. Please Please, help me with memo-fields, real problem

8. Please help with this problem!!ARRAY problem

9. Help - Problems with Query _AND_ insert

10. Please explain Sorting Methods

11. README PLEASE TQuery insert error

12. property write method's problem....

 

 
Powered by phpBB® Forum Software