MsgBox ("You must first enter a customer before checking their billing status.")
Exit Sub
Else
MousePointer = 11 ' hourglass
frmCustAccount.Show 1 'modal
End If
End Sub
Private Sub btnHelp_Click()
MsgBox ("Before entering any information, use the LOOKUP button to get a customer from the database, or create a new customer by selecting File|New Customer. Customer information is saved for each field when your cursor leaves the field.")
End Sub
Private Sub btnOrder_Click()
If Len(txtCustomerNum.Text) = 0 Then
MsgBox ("You must first enter a customer before ordering.")
Exit Sub
Else
MousePointer = 11 ' hourglass
frmOrder.Show 1 'modal
End If
End Sub
Private Sub btnFindCust_Click()
MousePointer = 11 ' hourglass
frmLookup.Show 1 'modal
End Sub
Private Sub custmain_Validate(Action As Integer, Save As Integer)
End Sub
Private Sub Form_Activate()
' Reset to the default pointer when returning to this form.
MousePointer = 0
' If there is an active customer,
' update the information on the screen.
If Len(Customer_number) <> 0 Then
Call UpdateInfo
End If
' Reset the mouse pointer to be the
' default pointer. Put the default focus on the
' Find Customer button.
MousePointer = 1
btnFindCust.SetFocus
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
' While not a Windows standard, the client
' prefers to use the enter key to move from field to field.
' This subroutine should trap the keypress and
' and process all "ENTER" keys as "TAB"
If Me.ActiveControl.Tag <> "Comment" Then
If KeyAscii = 13 Then
SendKeys "{tab}"
KeyAscii = 0
End If
End If
End Sub
Private Sub Form_Load()
Dim CustDB As Database
Dim CustCriteria As String
Dim Custset As Dynaset
Dim CustTable As Table
Dim Customer_number
just_deleted = False
'Center the form
Left = (Screen.Width - Width) / 2
Top = (Screen.Height - Height) / 2
' Initialize the GenComm data control
CustGenComm.DatabaseName = Database_name
CustGenComm.RecordSource = "Select * from CustGenComm where CustomerNum = 0;"
txtCustBal.Visible = False
End Sub
Private Sub mnuEditDelete_Click()
Call btnDelCust_Click
End Sub
Private Sub mnuEditFind_Click()
Call btnFindCust_Click
End Sub
Private Sub btnDelCust_Click()
Dim CustMainTbl As Table
Dim CustGenCommTbl As Table
Dim CustAccountTbl As Table
Dim CustProdTbl As Table
Dim CustBillAddrTbl As Table
Dim OrdersTbl As Table
Dim CustProdHistTbl As Table
Dim ProdOrdTbl As Table
Dim Qcriteria
Dim indexval As Integer
Dim delcust
If Len(Customer_number) = 0 Then
MsgBox ("Please use the lookup function to find the customer number you wish to delete.")
Exit Sub
End If
Set CustMainTbl = CustDB.OpenTable("CUSTMAIN")
CustMainTbl.Index = "PrimaryKey"
CustMainTbl.Seek "=", Customer_number
If (CustMainTbl.NoMatch = True) Then
MsgBox ("Can't find customer " & Customer_number)
Exit Sub
Else
' successfully read record.
delcust = MsgBox("REALLY delete customer " & Customer_number & " and ALL the associated information?", vbYesNo, "Delete " & Customer_number)
If delcust = 6 Then 'yes
MousePointer = 11 ' hourglass
' Delete this person from the customer main table
CustMainTbl.Delete
' CustGenCommTbl
' Delete this person from the general comments table
Set CustGenCommTbl = CustDB.OpenTable("CUSTGENCOMM")
CustGenCommTbl.Index = "PrimaryKey"
CustGenCommTbl.Seek "=", Customer_number
While (CustGenCommTbl.NoMatch = False)
CustGenCommTbl.Delete
CustGenCommTbl.Seek "=", Customer_number
Wend
' CustAccountTbl
' Delete this person from the Customer Account table
Set CustAccountTbl = CustDB.OpenTable("CUSTACCOUNT")
CustAccountTbl.Index = "CustomerNum"
CustAccountTbl.Seek "=", Customer_number
While (CustAccountTbl.NoMatch = False)
CustAccountTbl.Delete
CustAccountTbl.Seek "=", Customer_number
Wend
' CustProdTbl
' Delete this person from the Customer Products table
Set CustProdTbl = CustDB.OpenTable("CustProd")
CustProdTbl.Index = "CustomerNum"
CustProdTbl.Seek "=", Customer_number
While (CustProdTbl.NoMatch = False)
CustProdTbl.Delete
CustProdTbl.Seek "=", Customer_number
Wend
' OrdersTbl
' Delete this person from the Customer Orders table
Set OrdersTbl = CustDB.OpenTable("ORDERS")
OrdersTbl.Index = "CustomerNum"
OrdersTbl.Seek "=", Customer_number
While (OrdersTbl.NoMatch = False)
OrdersTbl.Delete
OrdersTbl.Seek "=", Customer_number
Wend
'* Delete this person from the Order History
Set CustProdHistTbl = CustDB.OpenTable("CustProdHist")
CustDB.Execute ("Delete * From CustProdHist Where CustomerNum = " & Customer_number & ";")
' ProdOrdTbl
' Delete this person from the Product Order table (This is not
' used by this application, but was part of the database
' conversion; the thought was it would be used someday).
Set ProdOrdTbl = CustDB.OpenTable("Orders")
ProdOrdTbl.Index = "PrimaryKey"
ProdOrdTbl.Seek "=", Customer_number
While (ProdOrdTbl.NoMatch = False)
ProdOrdTbl.Delete
ProdOrdTbl.Seek "=", Customer_number
Wend
' Initialize the GenComm data control
CustGenComm.RecordSource = "Select * from CustGenComm where CustomerNum = 0;"
CustGenComm.Refresh
' Initialize the Custmain data control
Qcriteria = "SELECT * FROM CUSTMAIN WHERE CustomerNum = 0;"
Set CustmainDynaset = CustDB.CreateDynaset(Qcriteria)
'custmain.Refresh
Customer_number = 0
' Blank out all of the fields.
txtFirstName.Text = ""
txtLastName.Text = ""
txtConame.Text = ""
txtAddrline1.Text = ""
txtAddrline2.Text = ""
txtCity.Text = ""
txtState.Text = ""
txtHomePhone.Text = ""
txtZip.Text = ""
txtHomePhone.Text = ""
txtWorkPhone.Text = ""
txtSalutation.Text = ""
txtCustomerNum.Text = ""
' Set the indicator for whether this customer has
' just been deleted or not so we don't give the
' user an message for attempting to do something without
' having an active customer
just_deleted = True
MousePointer = 0 ' default
Else
MsgBox ("Customer " & Customer_number & " NOT deleted.")
End If
End If
End Sub
Private Sub mnuEditNew_Click()
Call btnAddCust_Click
End Sub
Private Sub mnuFileExit_Click()
Unload Custinf
End Sub
Private Sub btnAddCust_Click()
Dim CustMainTbl As Table
Dim Qcriteria
Dim indexval As Integer
' Look in the customer table for an unused customer number.
Set CustMainTbl = CustDB.OpenTable("CUSTMAIN")
CustMainTbl.Index = "PrimaryKey"
indexval = 1
CustMainTbl.Seek "=", indexval
While (CustMainTbl.NoMatch = False)
indexval = indexval + 1
CustMainTbl.Seek "=", indexval
Wend
' Add this new customer to the customer table
CustMainTbl.AddNew
CustMainTbl.Fields("CustomerNum") = indexval
CustMainTbl.Update
' Make this new customer number the current customer_number
Customer_number = indexval
txtCustomerNum.Text = Customer_number
' Make this newly created record our current record
Qcriteria = "SELECT * FROM CUSTMAIN WHERE CustomerNum = " & Customer_number
Set CustmainDynaset = CustDB.CreateDynaset(Qcriteria)
'custmain.Refresh
Call UpdateInfo
End Sub
Private Sub mnuHelp_Click()
Call btnHelp_Click
End Sub
Private Sub mnuViewAccount_Click()
Call btnAccount_Click
End Sub
Private Sub mnuViewOrder_Click()
Call btnOrder_Click
End Sub
Private Sub txtAddrline1_LostFocus()
' If there is nothing in the field, of if nothing has changed,