Please Help! My code is Only Incrementing 1 Customer Record! 
Author Message
 Please Help! My code is Only Incrementing 1 Customer Record!

Hello All,..

I am trying to increment Invoice numbers in a database when the "New Invoice"
form is launched.

If I have a customer choosen in the main form's DBGrid, and I select the button
to launch the New Invoice form, the DBEdit on the New Invoice form for the
company name is filled in, and it keeps in sync with the Mainform's tables,.. I
have a call in the NewInvBtnClick handler that calls a procedure named
"NewInvoice" here is the TMainGridForm.NewInvoice procedure:
--------------------------------------------------------------------------------
procedure TMainGridForm.NewInvoice;
var
 nextOrder : Integer;
begin
 {Enter a new Order}

 InvoiceTable.Open;
 CustomerTable.Open;
 {Find the last Order}
 InvoiceTable.Last;
 nextOrder := InvoiceTable.FieldByName('InvoiceNum').AsInteger + 01;

 InvoiceTable.Append;
 InvoiceTable.FieldByName('InvoiceNum').AsInteger := nextOrder;
 NewInvoiceForm.Caption := 'New Invoice';

 NewInvoiceForm.CustomerDBEdit.Text := CustomerTable.FieldByName
  ('Company').AsString;
 NewInvoiceForm.InvNumDBEdit.Text := IntToStr(nextOrder);

 NewInvoiceForm.ShowModal;

{I have a "InvoiceTable.Post;" call in the Post button procedure in the
NewInvoice unit}
end;
------------------------------------------------------------------------------
This all works fine, for one customer,..  If I keep the cursor on one customer
in the DBGrid on the TMainGridForm, and choose the "NewInvoice" button multiple
times, the program will add a new invoice to the invoice table, and increment
the invoice number field accordingly, without a hitch..

But If there is lets say 2 invoices in the invoice table, and I choose a new
customer in the DBGrid, and then select the NewInvoice button to launch the New
Invoice form, to input another invoice in the invoice table for the newly
selected customer, the DBEdits on the NewInvoice form get filled in right, and
it posts to the Mainform's InvoiceTable, but the Invoice number does not get
incremented.. It is always at "1" for the second customer..???

Can someone tell me what might me going wrong??

Any help would be appreciated..

Thanks

----
RKR

****************************************

****************************************



Sat, 25 Jul 1998 03:00:00 GMT  
 Please Help! My code is Only Incrementing 1 Customer Record!

Quote:

>Hello All,..
>I am trying to increment Invoice numbers in a database when the "New Invoice"
>form is launched.
>If I have a customer choosen in the main form's DBGrid, and I select the button
>to launch the New Invoice form, the DBEdit on the New Invoice form for the
>company name is filled in, and it keeps in sync with the Mainform's tables,.. I
>have a call in the NewInvBtnClick handler that calls a procedure named
>"NewInvoice" here is the TMainGridForm.NewInvoice procedure:
>--------------------------------------------------------------------------------
>procedure TMainGridForm.NewInvoice;
>var
> nextOrder : Integer;
>begin
> {Enter a new Order}

> InvoiceTable.Open;
> CustomerTable.Open;
> {Find the last Order}
> InvoiceTable.Last;
> nextOrder := InvoiceTable.FieldByName('InvoiceNum').AsInteger + 01;
> InvoiceTable.Append;
> InvoiceTable.FieldByName('InvoiceNum').AsInteger := nextOrder;
> NewInvoiceForm.Caption := 'New Invoice';
> NewInvoiceForm.CustomerDBEdit.Text := CustomerTable.FieldByName
>  ('Company').AsString;
> NewInvoiceForm.InvNumDBEdit.Text := IntToStr(nextOrder);
> NewInvoiceForm.ShowModal;
>{I have a "InvoiceTable.Post;" call in the Post button procedure in the
>NewInvoice unit}
>end;
>------------------------------------------------------------------------------
>This all works fine, for one customer,..  If I keep the cursor on one customer
>in the DBGrid on the TMainGridForm, and choose the "NewInvoice" button multiple
>times, the program will add a new invoice to the invoice table, and increment
>the invoice number field accordingly, without a hitch..
>But If there is lets say 2 invoices in the invoice table, and I choose a new
>customer in the DBGrid, and then select the NewInvoice button to launch the New
>Invoice form, to input another invoice in the invoice table for the newly
>selected customer, the DBEdits on the NewInvoice form get filled in right, and
>it posts to the Mainform's InvoiceTable, but the Invoice number does not get
>incremented.. It is always at "1" for the second customer..???
>Can someone tell me what might me going wrong??

I suspect that you have a parent-child relationship between the two tables
such that only invoices related to the current customer are visible in the
invoice table.  That is, the invoice table cursor does not "see" the entire
table but only a restricted view.

Therefore, the invoice table is "empty," the asInteger of a null field is
zero, plus one is 1, and there you have it.

You could bypass the problem by having a second cursor to the Invoice table,
this one without a masterTable property, but let me caution you that in a
multi-user situation this strategy does not work.  When several people are
adding records at the same time they do not see one another's
edits-in-progress.  This problem is traditionally solved with some next-number
table with a single record, with code that locks that table, grabs the next
number, and unlocks it again -- which BTW "edit" will do.  The strongest
programs go one step further and use a Dbi call to set a retry-period on the
lock attempt, so that if for some reason the next-number table is locked for
an extended period, applications will time out and go away.

/mr/



Sat, 25 Jul 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. I am a beginner. Please help

2. Btrieve sucks and I am stupid please Help.

3. Please, please help me with this code.

4. I need help fixing this CASE Select code, please help

5. HELP *.dbt more dan 580MB with only 75 customers

6. I AM DESPERT !! Please helkp me

7. urgent - help me with my bad code!! please

8. urgent - help me with my bad code!! please

9. Inline Code Please Help!

10. Source code request ! Please Help

11. Limiting the number of records in a query (Urgent - please help)

12. Record Link List Help please

 

 
Powered by phpBB® Forum Software