home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "MAIN"
- ' Allow the user to set the database location
- Global Database_name
- Global CustDB As Database
-
- ' Placeholder for the home directory of this application
- Global App_location As String
-
- ' Snapshot for Custmain table
- Global CustmainSnapshot As Snapshot
- Global CustmainDynaset As Dynaset
-
- ' Customer number is the key to the database
- Global Customer_number
-
- ' Backup customer_number to restore in case user
- ' cancels an event which might change it.
- Global tmpCustNum
-
- ' Customer balance
- Global CurrentBalance As Double
-
- ' Indicator to prevent activity on a just deleted customer
- Global just_deleted
-
-
-
-
- Sub FillOrderTicketTable(ByVal Product As String)
-
- Dim OrderTicketTbl As Table
- Dim CustBillAddrTbl As Table
- Dim CustomerTbl As Table
- Dim CustProdTbl As Table
-
- Set OrderTicketTbl = CustDB.OpenTable("OrderTicket")
- Set CustomerTbl = CustDB.OpenTable("CustMain")
-
- ' Find the customer record
- CustomerTbl.Index = "PrimaryKey"
- CustomerTbl.Seek "=", Customer_number
- If (CustomerTbl.NoMatch = True) Then
- MsgBox ("The customer you have selected is not in the database.")
- Exit Sub
- End If
-
- OrderTicketTbl.AddNew
-
- OrderTicketTbl.Fields("CustomerNum") = Customer_number
- OrderTicketTbl.Fields("InvoiceDate") = Date$
- OrderTicketTbl.Fields("First_Name") = CustomerTbl.Fields("First_Name")
- OrderTicketTbl.Fields("Last_Name") = CustomerTbl.Fields("Last_Name")
- OrderTicketTbl.Fields("Company") = CustomerTbl.Fields("Company")
- OrderTicketTbl.Fields("Address") = CustomerTbl.Fields("Address")
- OrderTicketTbl.Fields("Suite_Apt") = CustomerTbl.Fields("Suite_Apt")
- OrderTicketTbl.Fields("PO_Box") = CustomerTbl.Fields("PO_Box")
- OrderTicketTbl.Fields("City") = CustomerTbl.Fields("City")
- OrderTicketTbl.Fields("State") = CustomerTbl.Fields("State")
- OrderTicketTbl.Fields("Zip") = CustomerTbl.Fields("Zip")
-
- ' Find the billing record
- Set CustBillAddrTbl = CustDB.OpenTable("CUSTBILLADDR")
- CustBillAddrTbl.Index = "PrimaryKey"
- CustBillAddrTbl.Seek "=", Customer_number
- If (CustBillAddrTbl.NoMatch = False) Then
- OrderTicketTbl.Fields("Billing_Name") = CustBillAddrTbl.Fields("Billing_Name")
- OrderTicketTbl.Fields("Billing_Address") = CustBillAddrTbl.Fields("Billing_Address")
- OrderTicketTbl.Fields("Billing_Apt") = CustBillAddrTbl.Fields("Billing_Apt")
- OrderTicketTbl.Fields("Billing_PO_Box") = CustBillAddrTbl.Fields("Billing_PO_Box")
- OrderTicketTbl.Fields("Billing_City") = CustBillAddrTbl.Fields("Billing_City")
- OrderTicketTbl.Fields("Billing_State") = CustBillAddrTbl.Fields("Billing_State")
- OrderTicketTbl.Fields("Billing_Zip") = CustBillAddrTbl.Fields("Billing_Zip")
- End If
-
- ' Find the customer product record
- Set CustProdTbl = CustDB.OpenTable("CustProd")
- CustProdTbl.Index = "Key1"
- CustProdTbl.Seek "=", Customer_number, Product
- If (CustProdTbl.NoMatch = True) Then
- MsgBox ("No product record found for this customer.")
- Exit Sub
- End If
-
- OrderTicketTbl.Fields("product") = CustProdTbl.Fields("product")
- OrderTicketTbl.Fields("Qty") = CustProdTbl.Fields("Qty")
- OrderTicketTbl.Fields("Price") = CustProdTbl.Fields("Price")
- OrderTicketTbl.Fields("Subtotal") = CustProdTbl.Fields("Subtotal")
- If CustProdTbl.Fields("Tax") > 0 Then
- OrderTicketTbl.Fields("Tax") = CustProdTbl.Fields("Subtotal") * 0.06
- OrderTicketTbl.Fields("Total") = CustProdTbl.Fields("Subtotal") & (CustProdTbl.Fields("Subtotal") * 0.06)
- Else
- OrderTicketTbl.Fields("Total") = CustProdTbl.Fields("Subtotal")
- End If
-
-
- OrderTicketTbl.Fields("Deposit") = CustProdTbl.Fields("Deposit")
- OrderTicketTbl.Update
-
- End Sub
-
- Sub MAIN()
-
- Cover_scr.Show
-
- End Sub
-
- Public Sub CalculateCurrentBalance()
-
- Dim RecSet As Snapshot
- Dim buffer As String
- Dim CustOrdTbl As Table
- Dim charge
- Dim credit
- Dim Tbl As Table
-
- ' Get all of the customers orders and subtract
- ' the credits from the charges.
- Set CustOrdTbl = CustDB.OpenTable("Orders")
- buffer = "Select Sum(Charge),Sum(Credit) From Orders Where CustomerNum = " & Str(Customer_number) & ";"
-
- Set RecSet = CustDB.CreateSnapshot(buffer)
-
- ' If there is no value, then the value is considered zero.
- If (IsNull(RecSet.Fields(0))) = True Then
- charge = 0
- Else
- charge = RecSet.Fields(0)
- End If
-
- If (IsNull(RecSet.Fields(1))) = True Then
- credit = 0
- Else
- credit = RecSet.Fields(1)
- End If
-
- ' Set the gloabal variable
- CurrentBalance = charge - credit
-
- ' close the order table
- CustOrdTbl.Close
-
- ' Now update the main customer table.
- Set Tbl = CustDB.OpenTable("CustMain")
- Tbl.Index = "PrimaryKey"
- Tbl.Seek "=", Customer_number
- If (Tbl.NoMatch = False) Then
- Tbl.Edit
- Tbl.Fields("Current_Balance") = CurrentBalance
- Tbl.Update
- End If
- Tbl.Close
-
-
- End Sub
-