home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / source / chap35 / custinf.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-11  |  30.5 KB  |  891 lines

  1. VERSION 4.00
  2. Begin VB.Form Custinf 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H00C0C0C0&
  5.    Caption         =   "Customer Information"
  6.    ClientHeight    =   6105
  7.    ClientLeft      =   270
  8.    ClientTop       =   1920
  9.    ClientWidth     =   8640
  10.    BeginProperty Font 
  11.       name            =   "MS Sans Serif"
  12.       charset         =   1
  13.       weight          =   700
  14.       size            =   8.25
  15.       underline       =   0   'False
  16.       italic          =   0   'False
  17.       strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H80000008&
  20.    Height          =   6795
  21.    KeyPreview      =   -1  'True
  22.    Left            =   210
  23.    LinkTopic       =   "Form1"
  24.    MaxButton       =   0   'False
  25.    ScaleHeight     =   6105
  26.    ScaleWidth      =   8640
  27.    Top             =   1290
  28.    Width           =   8760
  29.    Begin VB.CommandButton btnDelCust 
  30.       Caption         =   "Delete Customer"
  31.       Height          =   495
  32.       Left            =   3840
  33.       TabIndex        =   31
  34.       TabStop         =   0   'False
  35.       Top             =   120
  36.       Width           =   1575
  37.    End
  38.    Begin VB.CommandButton btnAddCust 
  39.       Caption         =   "Add Customer"
  40.       Height          =   495
  41.       Left            =   120
  42.       TabIndex        =   30
  43.       TabStop         =   0   'False
  44.       Top             =   120
  45.       Width           =   1935
  46.    End
  47.    Begin VB.CommandButton btnOrder 
  48.       Caption         =   "&Order"
  49.       Height          =   495
  50.       Left            =   6600
  51.       TabIndex        =   29
  52.       TabStop         =   0   'False
  53.       Top             =   120
  54.       Width           =   855
  55.    End
  56.    Begin VB.CommandButton btnAccount 
  57.       Caption         =   "&Account"
  58.       Height          =   495
  59.       Left            =   5520
  60.       TabIndex        =   28
  61.       TabStop         =   0   'False
  62.       Top             =   120
  63.       Width           =   975
  64.    End
  65.    Begin VB.CommandButton btnHelp 
  66.       Caption         =   "&Help"
  67.       Height          =   495
  68.       Left            =   7560
  69.       TabIndex        =   27
  70.       TabStop         =   0   'False
  71.       Top             =   120
  72.       Width           =   855
  73.    End
  74.    Begin VB.CommandButton btnClose 
  75.       Caption         =   "&Close"
  76.       Height          =   495
  77.       Left            =   7680
  78.       TabIndex        =   26
  79.       TabStop         =   0   'False
  80.       Top             =   5040
  81.       Width           =   855
  82.    End
  83.    Begin VB.TextBox txtFirstName 
  84.       Height          =   285
  85.       Left            =   1080
  86.       TabIndex        =   1
  87.       Top             =   720
  88.       Width           =   2535
  89.    End
  90.    Begin VB.TextBox txtLastName 
  91.       Height          =   285
  92.       Left            =   1080
  93.       TabIndex        =   2
  94.       Top             =   1080
  95.       Width           =   2535
  96.    End
  97.    Begin VB.TextBox txtAddrline1 
  98.       Height          =   285
  99.       Left            =   1080
  100.       TabIndex        =   4
  101.       Top             =   1800
  102.       Width           =   2535
  103.    End
  104.    Begin VB.TextBox txtCoName 
  105.       Height          =   285
  106.       Left            =   1080
  107.       TabIndex        =   3
  108.       Top             =   1440
  109.       Width           =   2535
  110.    End
  111.    Begin VB.TextBox txtAddrline2 
  112.       Height          =   285
  113.       Left            =   1080
  114.       TabIndex        =   5
  115.       Top             =   2160
  116.       Width           =   2535
  117.    End
  118.    Begin VB.TextBox txtCity 
  119.       Height          =   285
  120.       Left            =   1080
  121.       TabIndex        =   6
  122.       Top             =   2520
  123.       Width           =   1695
  124.    End
  125.    Begin VB.TextBox txtState 
  126.       Height          =   285
  127.       Left            =   3840
  128.       TabIndex        =   7
  129.       Top             =   2520
  130.       Width           =   615
  131.    End
  132.    Begin VB.TextBox txtCustBal 
  133.       Alignment       =   1  'Right Justify
  134.       BackColor       =   &H00C0C0C0&
  135.       BorderStyle     =   0  'None
  136.       BeginProperty Font 
  137.          name            =   "MS Sans Serif"
  138.          charset         =   1
  139.          weight          =   400
  140.          size            =   18
  141.          underline       =   0   'False
  142.          italic          =   0   'False
  143.          strikethrough   =   0   'False
  144.       EndProperty
  145.       Height          =   435
  146.       Left            =   6840
  147.       Locked          =   -1  'True
  148.       TabIndex        =   25
  149.       TabStop         =   0   'False
  150.       Top             =   960
  151.       Width           =   1455
  152.    End
  153.    Begin VB.TextBox txtSalutation 
  154.       Height          =   285
  155.       Left            =   3840
  156.       TabIndex        =   11
  157.       Top             =   3000
  158.       Width           =   1575
  159.    End
  160.    Begin VB.CommandButton btnFindCust 
  161.       Caption         =   "&Find Customer"
  162.       Height          =   495
  163.       Left            =   2160
  164.       TabIndex        =   24
  165.       TabStop         =   0   'False
  166.       Top             =   120
  167.       Width           =   1575
  168.    End
  169.    Begin VB.TextBox txtCustomerNum 
  170.       Appearance      =   0  'Flat
  171.       BackColor       =   &H00C0C0C0&
  172.       BorderStyle     =   0  'None
  173.       BeginProperty Font 
  174.          name            =   "MS Sans Serif"
  175.          charset         =   1
  176.          weight          =   400
  177.          size            =   18
  178.          underline       =   0   'False
  179.          italic          =   0   'False
  180.          strikethrough   =   0   'False
  181.       EndProperty
  182.       ForeColor       =   &H00C00000&
  183.       Height          =   495
  184.       Left            =   6840
  185.       Locked          =   -1  'True
  186.       TabIndex        =   23
  187.       TabStop         =   0   'False
  188.       Top             =   1560
  189.       Width           =   1215
  190.    End
  191.    Begin VB.TextBox txtWorkPhone 
  192.       Height          =   285
  193.       Left            =   1320
  194.       TabIndex        =   10
  195.       Top             =   3240
  196.       Width           =   1575
  197.    End
  198.    Begin VB.TextBox txtHomePhone 
  199.       Height          =   285
  200.       Left            =   1320
  201.       TabIndex        =   9
  202.       Top             =   2880
  203.       Width           =   1575
  204.    End
  205.    Begin VB.TextBox txtzip 
  206.       Height          =   285
  207.       Left            =   4560
  208.       TabIndex        =   8
  209.       Top             =   2520
  210.       Width           =   855
  211.    End
  212.    Begin VB.TextBox txtCustGenComm 
  213.       DataField       =   "General_Comments"
  214.       DataSource      =   "CustGenComm"
  215.       Height          =   1935
  216.       Left            =   120
  217.       MultiLine       =   -1  'True
  218.       ScrollBars      =   2  'Vertical
  219.       TabIndex        =   12
  220.       Tag             =   "Comment"
  221.       Top             =   3600
  222.       Width           =   7455
  223.    End
  224.    Begin VB.Data CustGenComm 
  225.       Appearance      =   0  'Flat
  226.       Caption         =   "CustGenComm"
  227.       Connect         =   ""
  228.       DatabaseName    =   "C:\VBPROJ\SAMS\VB4DB.MDB"
  229.       Exclusive       =   0   'False
  230.       Height          =   270
  231.       Left            =   3600
  232.       Options         =   0
  233.       ReadOnly        =   0   'False
  234.       RecordsetType   =   1  'Dynaset
  235.       RecordSource    =   "CUSTGENCOMM"
  236.       Top             =   5640
  237.       Visible         =   0   'False
  238.       Width           =   2775
  239.    End
  240.    Begin VB.Label Label11 
  241.       Alignment       =   1  'Right Justify
  242.       Appearance      =   0  'Flat
  243.       BackColor       =   &H00C0C0C0&
  244.       Caption         =   "Contact"
  245.       ForeColor       =   &H80000008&
  246.       Height          =   255
  247.       Left            =   3000
  248.       TabIndex        =   22
  249.       Top             =   3000
  250.       Width           =   735
  251.    End
  252.    Begin VB.Label Label10 
  253.       Alignment       =   1  'Right Justify
  254.       Appearance      =   0  'Flat
  255.       BackColor       =   &H00C0C0C0&
  256.       Caption         =   "Work phone"
  257.       ForeColor       =   &H80000008&
  258.       Height          =   255
  259.       Left            =   120
  260.       TabIndex        =   21
  261.       Top             =   3240
  262.       Width           =   1095
  263.    End
  264.    Begin VB.Label Label9 
  265.       Alignment       =   1  'Right Justify
  266.       Appearance      =   0  'Flat
  267.       BackColor       =   &H00C0C0C0&
  268.       Caption         =   "Home phone"
  269.       ForeColor       =   &H80000008&
  270.       Height          =   255
  271.       Left            =   120
  272.       TabIndex        =   20
  273.       Top             =   2880
  274.       Width           =   1095
  275.    End
  276.    Begin VB.Label Label8 
  277.       Alignment       =   1  'Right Justify
  278.       Appearance      =   0  'Flat
  279.       BackColor       =   &H00C0C0C0&
  280.       Caption         =   "Customer Number"
  281.       BeginProperty Font 
  282.          name            =   "MS Sans Serif"
  283.          charset         =   1
  284.          weight          =   700
  285.          size            =   9.75
  286.          underline       =   0   'False
  287.          italic          =   0   'False
  288.          strikethrough   =   0   'False
  289.       EndProperty
  290.       ForeColor       =   &H80000008&
  291.       Height          =   495
  292.       Left            =   5640
  293.       TabIndex        =   19
  294.       Top             =   1560
  295.       Width           =   975
  296.    End
  297.    Begin VB.Label Label3 
  298.       Alignment       =   1  'Right Justify
  299.       Appearance      =   0  'Flat
  300.       BackColor       =   &H00C0C0C0&
  301.       Caption         =   "Company"
  302.       ForeColor       =   &H80000008&
  303.       Height          =   255
  304.       Left            =   120
  305.       TabIndex        =   18
  306.       Top             =   1440
  307.       Width           =   855
  308.    End
  309.    Begin VB.Label Label2 
  310.       Alignment       =   1  'Right Justify
  311.       Appearance      =   0  'Flat
  312.       BackColor       =   &H00C0C0C0&
  313.       Caption         =   "State/Zip"
  314.       ForeColor       =   &H80000008&
  315.       Height          =   255
  316.       Left            =   2880
  317.       TabIndex        =   17
  318.       Top             =   2520
  319.       Width           =   855
  320.    End
  321.    Begin VB.Label Label7 
  322.       Alignment       =   1  'Right Justify
  323.       Appearance      =   0  'Flat
  324.       BackColor       =   &H00C0C0C0&
  325.       Caption         =   "Current Balance"
  326.       BeginProperty Font 
  327.          name            =   "MS Sans Serif"
  328.          charset         =   1
  329.          weight          =   700
  330.          size            =   9.75
  331.          underline       =   0   'False
  332.          italic          =   0   'False
  333.          strikethrough   =   0   'False
  334.       EndProperty
  335.       ForeColor       =   &H80000008&
  336.       Height          =   495
  337.       Left            =   5640
  338.       TabIndex        =   16
  339.       Top             =   960
  340.       Width           =   975
  341.    End
  342.    Begin VB.Label Label6 
  343.       Alignment       =   1  'Right Justify
  344.       Appearance      =   0  'Flat
  345.       BackColor       =   &H00C0C0C0&
  346.       Caption         =   "City"
  347.       ForeColor       =   &H80000008&
  348.       Height          =   255
  349.       Left            =   120
  350.       TabIndex        =   15
  351.       Top             =   2520
  352.       Width           =   855
  353.    End
  354.    Begin VB.Label Label5 
  355.       Alignment       =   1  'Right Justify
  356.       Appearance      =   0  'Flat
  357.       BackColor       =   &H00C0C0C0&
  358.       Caption         =   "Address"
  359.       ForeColor       =   &H80000008&
  360.       Height          =   255
  361.       Left            =   120
  362.       TabIndex        =   14
  363.       Top             =   1800
  364.       Width           =   855
  365.    End
  366.    Begin VB.Label Label4 
  367.       Alignment       =   1  'Right Justify
  368.       Appearance      =   0  'Flat
  369.       BackColor       =   &H00C0C0C0&
  370.       Caption         =   "Last name"
  371.       ForeColor       =   &H80000008&
  372.       Height          =   255
  373.       Left            =   0
  374.       LinkItem        =   "txtCustLastName"
  375.       TabIndex        =   13
  376.       Top             =   1080
  377.       Width           =   975
  378.    End
  379.    Begin VB.Label Label1 
  380.       Alignment       =   1  'Right Justify
  381.       Appearance      =   0  'Flat
  382.       BackColor       =   &H00C0C0C0&
  383.       Caption         =   "First name"
  384.       ForeColor       =   &H80000008&
  385.       Height          =   255
  386.       Left            =   0
  387.       TabIndex        =   0
  388.       Top             =   720
  389.       Width           =   975
  390.    End
  391.    Begin VB.Menu mnuFile 
  392.       Caption         =   "&File"
  393.       Begin VB.Menu mnuFileExit 
  394.          Caption         =   "E&xit"
  395.       End
  396.    End
  397.    Begin VB.Menu mnuEdit 
  398.       Caption         =   "&Edit"
  399.       Begin VB.Menu mnuEditFind 
  400.          Caption         =   "&Find Customer"
  401.       End
  402.       Begin VB.Menu mnuFileBar1 
  403.          Caption         =   "-"
  404.       End
  405.       Begin VB.Menu mnuEditNew 
  406.          Caption         =   "&Add customer"
  407.       End
  408.       Begin VB.Menu mnuFileBar2 
  409.          Caption         =   "-"
  410.       End
  411.       Begin VB.Menu mnuEditDelete 
  412.          Caption         =   "&Delete customer"
  413.       End
  414.    End
  415.    Begin VB.Menu mnuView 
  416.       Caption         =   "&View"
  417.       Begin VB.Menu mnuViewAccount 
  418.          Caption         =   "&Account Information"
  419.       End
  420.       Begin VB.Menu mnuViewOrder 
  421.          Caption         =   "&Order Form"
  422.       End
  423.    End
  424.    Begin VB.Menu mnuHelp 
  425.       Caption         =   "&Help"
  426.    End
  427. Attribute VB_Name = "Custinf"
  428. Attribute VB_Creatable = False
  429. Attribute VB_Exposed = False
  430. Private Sub btnClose_Click()
  431.     MousePointer = 11 ' hourglass
  432.     Unload Custinf
  433. End Sub
  434. Private Sub btnAccount_Click()
  435.     If Len(txtCustomerNum.Text) = 0 Then
  436.         MsgBox ("You must first enter a customer before checking their billing status.")
  437.         Exit Sub
  438.     Else
  439.         MousePointer = 11 ' hourglass
  440.         frmCustAccount.Show 1 'modal
  441.     End If
  442. End Sub
  443. Private Sub btnHelp_Click()
  444.     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.")
  445. End Sub
  446. Private Sub btnOrder_Click()
  447.     If Len(txtCustomerNum.Text) = 0 Then
  448.         MsgBox ("You must first enter a customer before ordering.")
  449.         Exit Sub
  450.     Else
  451.         MousePointer = 11 ' hourglass
  452.         frmOrder.Show 1 'modal
  453.     End If
  454. End Sub
  455. Private Sub btnFindCust_Click()
  456.         MousePointer = 11 ' hourglass
  457.         frmLookup.Show 1 'modal
  458. End Sub
  459. Private Sub custmain_Validate(Action As Integer, Save As Integer)
  460. End Sub
  461. Private Sub Form_Activate()
  462.     ' Reset to the default  pointer when returning to this form.
  463.     MousePointer = 0
  464.     ' If there is an active customer,
  465.     ' update the information on the screen.
  466.     If Len(Customer_number) <> 0 Then
  467.         Call UpdateInfo
  468.     End If
  469.     ' Reset the mouse pointer to be the
  470.     ' default pointer.  Put the default focus on the
  471.     ' Find Customer button.
  472.     MousePointer = 1
  473.     btnFindCust.SetFocus
  474. End Sub
  475. Private Sub Form_KeyPress(KeyAscii As Integer)
  476. ' While not a Windows standard, the client
  477. ' prefers to use the enter key to move from field to field.
  478. ' This subroutine should trap the keypress and
  479. ' and process all "ENTER" keys as "TAB"
  480.     If Me.ActiveControl.Tag <> "Comment" Then
  481.         If KeyAscii = 13 Then
  482.             SendKeys "{tab}"
  483.             KeyAscii = 0
  484.         End If
  485.     End If
  486. End Sub
  487. Private Sub Form_Load()
  488.     Dim CustDB As Database
  489.     Dim CustCriteria As String
  490.     Dim Custset As Dynaset
  491.     Dim CustTable As Table
  492.     Dim Customer_number
  493.     just_deleted = False
  494.     'Center the form
  495.     Left = (Screen.Width - Width) / 2
  496.     Top = (Screen.Height - Height) / 2
  497.     ' Initialize the GenComm data control
  498.     CustGenComm.DatabaseName = Database_name
  499.     CustGenComm.RecordSource = "Select * from CustGenComm where CustomerNum = 0;"
  500.     txtCustBal.Visible = False
  501. End Sub
  502. Private Sub mnuEditDelete_Click()
  503.     Call btnDelCust_Click
  504. End Sub
  505. Private Sub mnuEditFind_Click()
  506.     Call btnFindCust_Click
  507. End Sub
  508. Private Sub btnDelCust_Click()
  509. Dim CustMainTbl As Table
  510. Dim CustGenCommTbl As Table
  511. Dim CustAccountTbl As Table
  512. Dim CustProdTbl As Table
  513. Dim CustBillAddrTbl As Table
  514. Dim OrdersTbl As Table
  515. Dim CustProdHistTbl As Table
  516. Dim ProdOrdTbl As Table
  517. Dim Qcriteria
  518. Dim indexval As Integer
  519. Dim delcust
  520.     If Len(Customer_number) = 0 Then
  521.         MsgBox ("Please use the lookup function to find the customer number you wish to delete.")
  522.         Exit Sub
  523.     End If
  524.     Set CustMainTbl = CustDB.OpenTable("CUSTMAIN")
  525.     CustMainTbl.Index = "PrimaryKey"
  526.     CustMainTbl.Seek "=", Customer_number
  527.     If (CustMainTbl.NoMatch = True) Then
  528.         MsgBox ("Can't find customer " & Customer_number)
  529.         Exit Sub
  530.     Else
  531.         ' successfully read record.
  532.         delcust = MsgBox("REALLY delete customer " & Customer_number & " and ALL the associated information?", vbYesNo, "Delete " & Customer_number)
  533.         If delcust = 6 Then 'yes
  534.             MousePointer = 11 ' hourglass
  535.             
  536.             ' Delete this person from the customer main table
  537.             CustMainTbl.Delete
  538.             ' CustGenCommTbl
  539.             ' Delete this person from the general comments table
  540.             Set CustGenCommTbl = CustDB.OpenTable("CUSTGENCOMM")
  541.             
  542.             CustGenCommTbl.Index = "PrimaryKey"
  543.             CustGenCommTbl.Seek "=", Customer_number
  544.             While (CustGenCommTbl.NoMatch = False)
  545.                 CustGenCommTbl.Delete
  546.                 CustGenCommTbl.Seek "=", Customer_number
  547.             Wend
  548.             ' CustAccountTbl
  549.             ' Delete this person from the Customer Account table
  550.             Set CustAccountTbl = CustDB.OpenTable("CUSTACCOUNT")
  551.             CustAccountTbl.Index = "CustomerNum"
  552.             CustAccountTbl.Seek "=", Customer_number
  553.             While (CustAccountTbl.NoMatch = False)
  554.                 CustAccountTbl.Delete
  555.                 CustAccountTbl.Seek "=", Customer_number
  556.             Wend
  557.             ' CustProdTbl
  558.             ' Delete this person from the Customer Products table
  559.             Set CustProdTbl = CustDB.OpenTable("CustProd")
  560.             CustProdTbl.Index = "CustomerNum"
  561.             CustProdTbl.Seek "=", Customer_number
  562.             While (CustProdTbl.NoMatch = False)
  563.                 CustProdTbl.Delete
  564.                 CustProdTbl.Seek "=", Customer_number
  565.             Wend
  566.         
  567.             ' OrdersTbl
  568.             ' Delete this person from the Customer Orders table
  569.             Set OrdersTbl = CustDB.OpenTable("ORDERS")
  570.             OrdersTbl.Index = "CustomerNum"
  571.             OrdersTbl.Seek "=", Customer_number
  572.             While (OrdersTbl.NoMatch = False)
  573.                 OrdersTbl.Delete
  574.                 OrdersTbl.Seek "=", Customer_number
  575.             Wend
  576.             '* Delete this person from the Order History
  577.             Set CustProdHistTbl = CustDB.OpenTable("CustProdHist")
  578.             CustDB.Execute ("Delete * From CustProdHist Where CustomerNum = " & Customer_number & ";")
  579.             ' ProdOrdTbl
  580.             ' Delete this person from the Product Order table (This is not
  581.             ' used by this application, but was part of the database
  582.             ' conversion; the thought was it would be used someday).
  583.             Set ProdOrdTbl = CustDB.OpenTable("Orders")
  584.             ProdOrdTbl.Index = "PrimaryKey"
  585.             ProdOrdTbl.Seek "=", Customer_number
  586.             While (ProdOrdTbl.NoMatch = False)
  587.                 ProdOrdTbl.Delete
  588.                 ProdOrdTbl.Seek "=", Customer_number
  589.             Wend
  590.             ' Initialize the GenComm data control
  591.             CustGenComm.RecordSource = "Select * from CustGenComm where CustomerNum = 0;"
  592.             CustGenComm.Refresh
  593.       
  594.             ' Initialize the Custmain data control
  595.             Qcriteria = "SELECT * FROM CUSTMAIN WHERE CustomerNum = 0;"
  596.             Set CustmainDynaset = CustDB.CreateDynaset(Qcriteria)
  597.             'custmain.Refresh
  598.             Customer_number = 0
  599.             ' Blank out all of the fields.
  600.             txtFirstName.Text = ""
  601.             txtLastName.Text = ""
  602.             txtConame.Text = ""
  603.             txtAddrline1.Text = ""
  604.             txtAddrline2.Text = ""
  605.             txtCity.Text = ""
  606.             txtState.Text = ""
  607.             txtHomePhone.Text = ""
  608.             txtZip.Text = ""
  609.             txtHomePhone.Text = ""
  610.             txtWorkPhone.Text = ""
  611.             txtSalutation.Text = ""
  612.             txtCustomerNum.Text = ""
  613.             
  614.             ' Set the indicator for whether this customer has
  615.             ' just been deleted or not so we don't give the
  616.             ' user an message for attempting to do something without
  617.             ' having an active customer
  618.             just_deleted = True
  619.             MousePointer = 0 ' default
  620.         Else
  621.             MsgBox ("Customer " & Customer_number & " NOT deleted.")
  622.         End If
  623.     End If
  624. End Sub
  625. Private Sub mnuEditNew_Click()
  626.     Call btnAddCust_Click
  627. End Sub
  628. Private Sub mnuFileExit_Click()
  629.     Unload Custinf
  630. End Sub
  631. Private Sub btnAddCust_Click()
  632. Dim CustMainTbl As Table
  633. Dim Qcriteria
  634. Dim indexval As Integer
  635.     ' Look in the customer table for an unused customer number.
  636.     Set CustMainTbl = CustDB.OpenTable("CUSTMAIN")
  637.     CustMainTbl.Index = "PrimaryKey"
  638.     indexval = 1
  639.     CustMainTbl.Seek "=", indexval
  640.     While (CustMainTbl.NoMatch = False)
  641.         indexval = indexval + 1
  642.         CustMainTbl.Seek "=", indexval
  643.     Wend
  644.     ' Add this new customer to the customer table
  645.     CustMainTbl.AddNew
  646.     CustMainTbl.Fields("CustomerNum") = indexval
  647.     CustMainTbl.Update
  648.     ' Make this new customer number the current customer_number
  649.     Customer_number = indexval
  650.     txtCustomerNum.Text = Customer_number
  651.     ' Make this newly created record our current record
  652.     Qcriteria = "SELECT * FROM CUSTMAIN WHERE CustomerNum = " & Customer_number
  653.     Set CustmainDynaset = CustDB.CreateDynaset(Qcriteria)
  654.     'custmain.Refresh
  655.     Call UpdateInfo
  656. End Sub
  657. Private Sub mnuHelp_Click()
  658.     Call btnHelp_Click
  659. End Sub
  660. Private Sub mnuViewAccount_Click()
  661.     Call btnAccount_Click
  662. End Sub
  663. Private Sub mnuViewOrder_Click()
  664.     Call btnOrder_Click
  665. End Sub
  666. Private Sub txtAddrline1_LostFocus()
  667.     ' If there is nothing in the field, of if nothing has changed,
  668.     ' then do nothing.
  669. '    If Len(txtAddrline1.Text) = 0 Then
  670. '        Exit Sub
  671. '    End If
  672.     If txtAddrline1.DataChanged = True Then
  673.         Call UpdateField(ByVal txtAddrline1.Text, "Address")
  674.     End If
  675. End Sub
  676. Private Sub txtAddrline2_LostFocus()
  677.     If txtAddrline2.DataChanged = True Then
  678.         Call UpdateField(ByVal txtAddrline2, "Suite_Apt")
  679.     End If
  680. End Sub
  681. Private Sub txtCity_LostFocus()
  682.     If txtCity.DataChanged = True Then
  683.         Call UpdateField(ByVal txtCity, "City")
  684.     End If
  685. End Sub
  686. Private Sub txtCoName_LostFocus()
  687.     If txtConame.DataChanged = True Then
  688.         Call UpdateField(ByVal txtConame, "Company")
  689.     End If
  690. End Sub
  691. Private Sub txtCustGenComm_LostFocus()
  692. Dim CustGenCommDynaset As Dynaset
  693. Dim tmptext ' store value of comment text before creating new record
  694.     ' Check to see if a customer has been brought up.  If not, then do nothing.
  695.     If Len(Customer_number) <> 0 Then
  696.         'Check to see if this is a new record for this customer.  If so,
  697.         'add it to the database.
  698.         If CustGenComm.Recordset.RecordCount = 0 Then
  699.             tmptext = txtCustGenComm.Text
  700.             ' Get a record for the dynaset and then create it.
  701.             Qcriteria = "SELECT * FROM CustGenComm"
  702.             Set CustGenCommDynaset = CustDB.CreateDynaset(Qcriteria)
  703.             CustGenComm.Refresh     ' Update the data control
  704.             ' Add a new record to the dynaset and update the fields
  705.             CustGenCommDynaset.AddNew
  706.             
  707.             CustGenCommDynaset.Fields("CustomerNum") = Customer_number
  708.             CustGenCommDynaset.Fields("General_Comments") = tmptext
  709.             CustGenCommDynaset.Update
  710.             Qcriteria = "SELECT * FROM CUSTGENCOMM WHERE CustomerNum = " & Customer_number
  711.             CustGenComm.RecordSource = Qcriteria
  712.         Else
  713.             If Len(txtCustGenComm.Text) > 0 Then
  714.                 CustGenComm.Recordset.Edit
  715.                 CustGenComm.Recordset.Fields("General_Comments") = txtCustGenComm
  716.                 CustGenComm.Recordset.Update
  717.             Else
  718.                 CustGenComm.Recordset.Delete
  719.             End If
  720.         End If
  721.         CustGenComm.Refresh     ' update the data control
  722.     End If
  723. End Sub
  724. Private Sub txtCustomerNum_KeyPress(KeyAscii As Integer)
  725. ' While not a Windows standard, the client
  726. ' prefers to use the enter key to move from field to field.
  727. ' This subroutine should trap the keypress and
  728. ' and process all "ENTER" keys as "TAB"
  729.     If KeyAscii = 13 Then
  730.         SendKeys "{tab}"
  731.         KeyAscii = 0
  732.     End If
  733. End Sub
  734. Private Sub txtCustomerNum_LostFocus()
  735. Dim mboxret
  736.     If txtCustomerNum.Text <> Customer_number Then
  737.         mboxret = MsgBox("You can not change a customer's number.", MB_ICONEXCLAMATION)
  738.         txtCustomerNum.Text = Customer_number
  739.     End If
  740. End Sub
  741. Private Sub txtFirstName_LostFocus()
  742.     If txtFirstName.DataChanged = True Then
  743.         Call UpdateField(ByVal txtFirstName, "First_Name")
  744.     End If
  745. End Sub
  746. Private Sub txtHomePhone_LostFocus()
  747.     If txtHomePhone.DataChanged = True Then
  748.         Call UpdateField(ByVal txtHomePhone, "Home_Phone")
  749.     End If
  750. End Sub
  751. Private Sub txtLastName_LostFocus()
  752. Dim Qcriteria
  753. Dim tmpname
  754. Dim namechg
  755.     ' If there is nothing in the field, then do nothing.
  756.     'If Len(txtLastName.Text) = 0 Then
  757.     '    Exit Sub
  758.     'End If
  759.     ' No change, nothing to do to the field
  760.     If (txtLastName.DataChanged) = True Then
  761.         Call UpdateField(ByVal txtLastName, "Last_Name")
  762.     End If
  763. End Sub
  764. Private Sub txtSalutation_LostFocus()
  765.     If txtSalutation.DataChanged = True Then
  766.         Call UpdateField(ByVal txtSalutation, "Whose_Phone")
  767.     End If
  768. End Sub
  769. Private Sub txtState_LostFocus()
  770.     If txtState.DataChanged = True Then
  771.         Call UpdateField(ByVal txtState, "State")
  772.     End If
  773. End Sub
  774. Private Sub txtWorkPhone_LostFocus()
  775.     If txtWorkPhone.DataChanged = True Then
  776.         Call UpdateField(ByVal txtWorkPhone, "Work_Phone")
  777.     End If
  778. End Sub
  779. Private Sub txtZip_LostFocus()
  780.     If txtZip.DataChanged = True Then
  781.         Call UpdateField(ByVal txtZip, "Zip")
  782.     End If
  783. End Sub
  784. ' This subroutine Updates any field in the CUSTMAIN table.
  785. Private Sub UpdateField(ByVal FldText As String, fldName As String)
  786. Dim SqlUpdateCustmain
  787.     If (Len(Customer_number) = 0 Or Customer_number = 0) And Len(FldText) <> 0 Then
  788.         MsgBox ("You must Find or Create a new customer before adding data.")
  789.         Exit Sub
  790.     End If
  791.     If Len(FldText) <> 0 Then
  792.         ' Change the value in the table field
  793.         SqlUpdateCustmain = "UPDATE CUSTMAIN SET " & fldName & " = """ & FldText & """"
  794.     Else
  795.         ' Set the value in the table field to blank
  796.         SqlUpdateCustmain = "UPDATE CUSTMAIN SET " & fldName & " = NULL"
  797.     End If
  798.     ' Put the rest of the update string on.
  799.     SqlUpdateCustmain = SqlUpdateCustmain & " WHERE CustomerNum = " & Customer_number
  800.     CustDB.Execute SqlUpdateCustmain
  801. End Sub
  802. Private Sub UpdateInfo()
  803.         If just_deleted = True Then
  804.             just_deleted = False
  805.             Exit Sub
  806.         End If
  807.         ' If there's nobody in the database, then clean out the fields.
  808.         If Customer_number = 0 Or Customer_number = Null Then
  809.             Exit Sub
  810.         End If
  811.         'Check for existence of data in the fields to
  812.         ' avoid the invalid use of null error.
  813.         If IsNull(CustmainDynaset.Fields("First_Name")) = False Then
  814.             txtFirstName = CustmainDynaset.Fields("First_Name")
  815.         Else
  816.             txtFirstName.Text = ""
  817.         End If
  818.         
  819.         If IsNull(CustmainDynaset.Fields("Last_Name")) = False Then
  820.             txtLastName = CustmainDynaset.Fields("Last_Name")
  821.         Else
  822.             txtLastName.Text = ""
  823.         End If
  824.         If IsNull(CustmainDynaset.Fields("Current_Balance")) = False Then
  825.             txtCustBal.Visible = True
  826.             txtCustBal = CustmainDynaset.Fields("Current_Balance")
  827.         Else
  828.             txtCustBal.Visible = False
  829.         End If
  830.         If IsNull(CustmainDynaset.Fields("Company")) = False Then
  831.             txtConame = CustmainDynaset.Fields("Company")
  832.         Else
  833.             txtConame.Text = ""
  834.         End If
  835.         If IsNull(CustmainDynaset.Fields("Address")) = False Then
  836.             txtAddrline1 = CustmainDynaset.Fields("Address")
  837.         Else
  838.             txtAddrline1.Text = ""
  839.         End If
  840.         
  841.         ' In txtAddr2, put in either the Suite_Apt info or PO box,
  842.         ' since only one or the other will have data if either of
  843.         ' them have any data.
  844.         If IsNull(CustmainDynaset.Fields("Suite_Apt")) = False Then
  845.             txtAddrline2 = CustmainDynaset.Fields("Suite_Apt")
  846.         Else
  847.                 txtAddrline2.Text = ""
  848.         End If
  849.         If IsNull(CustmainDynaset.Fields("City")) = False Then
  850.             txtCity = CustmainDynaset.Fields("City")
  851.         Else
  852.             txtCity.Text = ""
  853.         End If
  854.         If IsNull(CustmainDynaset.Fields("State")) = False Then
  855.             txtState = CustmainDynaset.Fields("State")
  856.         Else
  857.             txtState.Text = ""
  858.         End If
  859.         If IsNull(CustmainDynaset.Fields("Zip")) = False Then
  860.             txtZip = CustmainDynaset.Fields("Zip")
  861.         Else
  862.             txtZip.Text = ""
  863.         End If
  864.         If IsNull(CustmainDynaset.Fields("Home_Phone")) = False Then
  865.             txtHomePhone = CustmainDynaset.Fields("Home_Phone")
  866.         Else
  867.             txtHomePhone.Text = ""
  868.         End If
  869.         If IsNull(CustmainDynaset.Fields("Work_Phone")) = False Then
  870.             txtWorkPhone = CustmainDynaset.Fields("Work_Phone")
  871.         Else
  872.             txtWorkPhone.Text = ""
  873.         End If
  874.         If IsNull(CustmainDynaset.Fields("Whose_Phone")) = False Then
  875.             txtSalutation = CustmainDynaset.Fields("Whose_Phone")
  876.         Else
  877.             txtSalutation.Text = ""
  878.         End If
  879.         
  880.         If IsNull(CustmainDynaset.Fields("CustomerNum")) = False Then
  881.             txtCustomerNum = CustmainDynaset.Fields("CustomerNum")
  882.         Else
  883.             txtCustomerNum.Text = 0
  884.         End If
  885.         Customer_number = txtCustomerNum.Text
  886.         ' Update the customer comment field
  887.         CustGenComm.RecordSource = "Select * from CustGenComm where CustomerNum = " & Customer_number & ";"
  888.         CustGenComm.Refresh
  889.         
  890. End Sub
  891.