Creating invoice

the bard

Registered User.
Local time
Today, 16:46
Joined
Oct 4, 2007
Messages
60
I am a novice to VB. I am creating an invoice form from a database. I have allowed for a maximum of 5 items. I have created code to calculate each item total price (Total1 = Price1*Quantity etc). These are then sutotalled, carriage added, vat calculated and grand totalled. This works well, but only if there are 5 items, any less and it will not run. I have tried setting default value of each total to 0, and I also created code

Dm Total2
If Quantity2 = "" Then
Total2 = 0
Else If Quantity = "*" Then
Total2 = Price2*Quantity2
End If

But this just will not run and I cannot understand the debugging.

Can anybody set me straight?
 
Hey, welcome to the forum.
I believe you have a table design problem. The easiest way to manage invoices is with two tables, tInvoice and tInvoiceDetail.

tInvoice
InvoiceID (PK) - invoice number
CustomerID (FK) - linked table not shown
Date

tInvoiceDetail
InvoiceDetailID (PK)
InvoiceID (FK) - link to tInvoice
ProductID (FK) - linked table not shown
Quantity
UnitCost

With a structure like this you can have any number of items on an invoice. You sum the items using SQL like ...

SELECT Sum(Quantity * UnitCost) as TotalInvoice
FROM tInvoiceDetail
WHERE InvoiceID = 456

In relational databases, if you find yourself using field names like Quantity1, Quantity2, Quantity3, etc...in a single record, then 99% of the time you'll make your life much easier by creating a one-to-many relationship between two tables.
 

Users who are viewing this thread

Back
Top Bottom