Board index » delphi » Can someone HELP with Filling DBEdit's Value's

Can someone HELP with Filling DBEdit's Value's

Can someone help??
I am writing a database for my business and cannot figure this out. (Paradox
format)

I have two forms: CustomerData & InvoiceEntry.

I cannot get the Invoice Number to fill into the InvoiceEntry Form's
InvNumDBEdit.

I have the code below attached to a speedbutton ("NewInvoiceBtn" on the
Customer Data Form) that shows the Invoice Entry Form, adds the appropriate
values from the Customer Data Form (using TField objects) to the Invoice Entry
Form's DBEdit objects.

Here's the code:

---------------------------------------------------------------------------

procedure TCustomerForm.NewInvoiceBtnClick(Sender: TObject);
begin
with InvoiceEntryForm.InvoiceTable do
 begin
 DisableControls;
 Insert;

 InvoiceEntryForm.InvoiceTableCompany.Value :=
    CustomerForm.CustomerTableCompany.Value;
 InvoiceEntryForm.InvoiceTableCustNum.Value :=
    CustomerForm.CustomerTableCustNum.Value;
 InvoiceEntryForm.InvoiceTableCustomerID.Value :=
    CustomerForm.CustomerTableCustomerID.Value;

 EnableControls;
 InvoiceEntryForm.Refresh;
 InvoiceEntryForm.Show;
 end;
end;
-----------------------------------------------------------------

This works for the fields involved..

But what code can I insert above "EnableControls;" that will look at the
Invoice.DB database "InvoiceNum" field for the last record (or highest number)
it contains and insert the new number (incrementing the old) into the new
invoice record when the invoice entry screen is created??

I tried setting the fields property type to "Autoincrement" in Database
Desktop, but cannot understand why when you are adding an invoice, and cancel
with the DBNavigator, the field still gets incremented.

EXAMPLE: Invoice.DB contains 2 records

I put the DBNavigator into Insert Mode, added a value in the fields of a new
record, cancel or abort the changes.. Put DBNavigator again into Insert Mode,
and the InvoiceNum value is increased like the the last cancel did not cancel.  
Now the InvoiceNum field has a value of 3 ???

If someone could take my blindfold off, or at least point me in the direction of
success, I would be greatly apreciative!!!

Thanks

----
RKR

****************************************
E-Mail:  r...@primenet.com
****************************************

 

Re:Can someone HELP with Filling DBEdit's Value's


Quote
r...@primenet.com wrote:
>Can someone help??

[ Code Delete ]

Quote
>This works for the fields involved..
>But what code can I insert above "EnableControls;" that will look at the
>Invoice.DB database "InvoiceNum" field for the last record (or highest number)
>it contains and insert the new number (incrementing the old) into the new
>invoice record when the invoice entry screen is created??

I assume that your Invoice field is indexed.  Try something like the
following (sorry I didn't use your field names):

  IndexName := 'MY_INV_IDX'; {Set the table to use the invoice index}
  Last;
  NewInvoice := FieldByName('INVOICE_NUM').AsInteger + 1;

  { Do other stuff }

  if (I want to keep changes) then
    begin
      FieldByName('INVOICE_NUM').AsInteger := NewInvoice;
    end
  else
    begin
      { Do whatever you need to cancel the new invoice }
    end;

I hope this helps.

**************************************************************************
* Ken Carpenter                 * "Stop your foul whining you {*word*127}     *
* Software Design & Development *  piece of distended rectum!"           *
* Network Group                 *    -- A.J. Rimmer to A.J. Rimmer       *
* Delta Controls Inc.           *       Aboard the mining ship Red Dwarf *
**************************************************************************

Other Threads