home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / gridex / frmcusto.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-01-02  |  12.8 KB  |  408 lines

  1. VERSION 5.00
  2. Begin VB.Form frmCustomers 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Customers"
  5.    ClientHeight    =   4875
  6.    ClientLeft      =   1485
  7.    ClientTop       =   2370
  8.    ClientWidth     =   7710
  9.    BeginProperty Font 
  10.       Name            =   "Tahoma"
  11.       Size            =   8.25
  12.       Charset         =   0
  13.       Weight          =   400
  14.       Underline       =   0   'False
  15.       Italic          =   0   'False
  16.       Strikethrough   =   0   'False
  17.    EndProperty
  18.    Icon            =   "frmCustomers.frx":0000
  19.    LinkTopic       =   "Form1"
  20.    LockControls    =   -1  'True
  21.    MaxButton       =   0   'False
  22.    MinButton       =   0   'False
  23.    ScaleHeight     =   325
  24.    ScaleMode       =   3  'Pixel
  25.    ScaleWidth      =   514
  26.    StartUpPosition =   2  'CenterScreen
  27.    Begin VB.TextBox txtField 
  28.       Height          =   345
  29.       Index           =   3
  30.       Left            =   5100
  31.       TabIndex        =   3
  32.       Top             =   1515
  33.       Width           =   2340
  34.    End
  35.    Begin VB.CommandButton cmdCancel 
  36.       Cancel          =   -1  'True
  37.       Caption         =   "Cancel"
  38.       Height          =   360
  39.       Left            =   3840
  40.       TabIndex        =   12
  41.       Top             =   4470
  42.       Width           =   1200
  43.    End
  44.    Begin VB.CommandButton cmdOK 
  45.       Caption         =   "OK"
  46.       Default         =   -1  'True
  47.       Height          =   360
  48.       Left            =   2535
  49.       TabIndex        =   11
  50.       Top             =   4470
  51.       Width           =   1200
  52.    End
  53.    Begin VB.TextBox txtField 
  54.       Height          =   720
  55.       Index           =   4
  56.       Left            =   1260
  57.       MultiLine       =   -1  'True
  58.       TabIndex        =   4
  59.       Top             =   1935
  60.       Width           =   6180
  61.    End
  62.    Begin VB.TextBox txtField 
  63.       Height          =   345
  64.       Index           =   9
  65.       Left            =   5100
  66.       TabIndex        =   10
  67.       Top             =   3750
  68.       Width           =   1800
  69.    End
  70.    Begin VB.ComboBox cboCountry 
  71.       Height          =   315
  72.       Left            =   5100
  73.       TabIndex        =   8
  74.       Top             =   3300
  75.       Width           =   1800
  76.    End
  77.    Begin VB.TextBox txtField 
  78.       Height          =   345
  79.       Index           =   6
  80.       Left            =   5100
  81.       TabIndex        =   6
  82.       Top             =   2835
  83.       Width           =   1800
  84.    End
  85.    Begin VB.TextBox txtField 
  86.       Height          =   345
  87.       Index           =   8
  88.       Left            =   1260
  89.       TabIndex        =   9
  90.       Top             =   3750
  91.       Width           =   2340
  92.    End
  93.    Begin VB.TextBox txtField 
  94.       Height          =   345
  95.       Index           =   7
  96.       Left            =   1260
  97.       TabIndex        =   7
  98.       Top             =   3285
  99.       Width           =   2340
  100.    End
  101.    Begin VB.TextBox txtField 
  102.       Height          =   345
  103.       Index           =   5
  104.       Left            =   1260
  105.       TabIndex        =   5
  106.       Top             =   2835
  107.       Width           =   2340
  108.    End
  109.    Begin VB.TextBox txtField 
  110.       Height          =   345
  111.       Index           =   2
  112.       Left            =   1260
  113.       TabIndex        =   2
  114.       Top             =   1515
  115.       Width           =   3150
  116.    End
  117.    Begin VB.TextBox txtField 
  118.       Height          =   345
  119.       Index           =   1
  120.       Left            =   1260
  121.       TabIndex        =   1
  122.       Top             =   1110
  123.       Width           =   6180
  124.    End
  125.    Begin VB.TextBox txtField 
  126.       Height          =   345
  127.       Index           =   0
  128.       Left            =   1260
  129.       TabIndex        =   0
  130.       Top             =   690
  131.       Width           =   1485
  132.    End
  133.    Begin VB.Image Image1 
  134.       Height          =   480
  135.       Left            =   180
  136.       Picture         =   "frmCustomers.frx":014A
  137.       Top             =   30
  138.       Width           =   480
  139.    End
  140.    Begin VB.Label lblName 
  141.       Alignment       =   1  'Right Justify
  142.       BackColor       =   &H80000003&
  143.       Caption         =   "Customers "
  144.       BeginProperty Font 
  145.          Name            =   "Tahoma"
  146.          Size            =   18
  147.          Charset         =   0
  148.          Weight          =   700
  149.          Underline       =   0   'False
  150.          Italic          =   0   'False
  151.          Strikethrough   =   0   'False
  152.       EndProperty
  153.       ForeColor       =   &H8000000E&
  154.       Height          =   525
  155.       Left            =   0
  156.       TabIndex        =   24
  157.       Top             =   0
  158.       Width           =   7710
  159.    End
  160.    Begin VB.Label lblField 
  161.       AutoSize        =   -1  'True
  162.       Caption         =   "Title:"
  163.       Height          =   195
  164.       Index           =   2
  165.       Left            =   4680
  166.       TabIndex        =   23
  167.       Top             =   1590
  168.       Width           =   360
  169.    End
  170.    Begin VB.Line Line1 
  171.       BorderColor     =   &H80000014&
  172.       Index           =   1
  173.       X1              =   0
  174.       X2              =   505
  175.       Y1              =   289
  176.       Y2              =   289
  177.    End
  178.    Begin VB.Line Line1 
  179.       BorderColor     =   &H80000010&
  180.       Index           =   0
  181.       X1              =   0
  182.       X2              =   505
  183.       Y1              =   288
  184.       Y2              =   288
  185.    End
  186.    Begin VB.Label lblField 
  187.       AutoSize        =   -1  'True
  188.       Caption         =   "Address:"
  189.       Height          =   195
  190.       Index           =   4
  191.       Left            =   555
  192.       TabIndex        =   22
  193.       Top             =   1995
  194.       Width           =   645
  195.    End
  196.    Begin VB.Label lblField 
  197.       AutoSize        =   -1  'True
  198.       Caption         =   "Fax:"
  199.       Height          =   195
  200.       Index           =   10
  201.       Left            =   4710
  202.       TabIndex        =   21
  203.       Top             =   3825
  204.       Width           =   330
  205.    End
  206.    Begin VB.Label lblField 
  207.       AutoSize        =   -1  'True
  208.       Caption         =   "Phone:"
  209.       Height          =   195
  210.       Index           =   9
  211.       Left            =   705
  212.       TabIndex        =   20
  213.       Top             =   3825
  214.       Width           =   510
  215.    End
  216.    Begin VB.Label lblField 
  217.       AutoSize        =   -1  'True
  218.       Caption         =   "Country:"
  219.       Height          =   195
  220.       Index           =   8
  221.       Left            =   4395
  222.       TabIndex        =   19
  223.       Top             =   3360
  224.       Width           =   645
  225.    End
  226.    Begin VB.Label lblField 
  227.       AutoSize        =   -1  'True
  228.       Caption         =   "Postal Code:"
  229.       Height          =   195
  230.       Index           =   7
  231.       Left            =   300
  232.       TabIndex        =   18
  233.       Top             =   3360
  234.       Width           =   915
  235.    End
  236.    Begin VB.Label lblField 
  237.       AutoSize        =   -1  'True
  238.       Caption         =   "Region:"
  239.       Height          =   195
  240.       Index           =   6
  241.       Left            =   4485
  242.       TabIndex        =   17
  243.       Top             =   2910
  244.       Width           =   555
  245.    End
  246.    Begin VB.Label lblField 
  247.       AutoSize        =   -1  'True
  248.       Caption         =   "City:"
  249.       Height          =   195
  250.       Index           =   5
  251.       Left            =   870
  252.       TabIndex        =   16
  253.       Top             =   2910
  254.       Width           =   345
  255.    End
  256.    Begin VB.Label lblField 
  257.       AutoSize        =   -1  'True
  258.       Caption         =   "Contact Name:"
  259.       Height          =   195
  260.       Index           =   3
  261.       Left            =   120
  262.       TabIndex        =   15
  263.       Top             =   1590
  264.       Width           =   1080
  265.    End
  266.    Begin VB.Label lblField 
  267.       AutoSize        =   -1  'True
  268.       Caption         =   "Company Name:"
  269.       Height          =   195
  270.       Index           =   1
  271.       Left            =   15
  272.       TabIndex        =   14
  273.       Top             =   1155
  274.       Width           =   1185
  275.    End
  276.    Begin VB.Label lblField 
  277.       AutoSize        =   -1  'True
  278.       Caption         =   "Customer ID:"
  279.       Height          =   195
  280.       Index           =   0
  281.       Left            =   240
  282.       TabIndex        =   13
  283.       Top             =   765
  284.       Width           =   960
  285.    End
  286. Attribute VB_Name = "frmCustomers"
  287. Attribute VB_GlobalNameSpace = False
  288. Attribute VB_Creatable = False
  289. Attribute VB_PredeclaredId = True
  290. Attribute VB_Exposed = False
  291. Option Explicit
  292. Dim m_db As Database
  293. Dim mrstCustomers As Recordset
  294. Dim mvarBookmark As Variant
  295. Dim mbIsNew As Boolean
  296. Public Key As String
  297. Private Const fldCustomerID = 0
  298. Private Const fldCompanyName = 1
  299. Private Const fldContactName = 2
  300. Private Const fldContactTitle = 3
  301. Private Const fldAddress = 4
  302. Private Const fldCity = 5
  303. Private Const fldRegion = 6
  304. Private Const fldPostalCode = 7
  305. Private Const fldPhone = 8
  306. Private Const fldFax = 9
  307. Private Const fldCountry = 10
  308. Dim m_DataChanged(10) As Boolean
  309. Public Sub EditRecord(db As Database, rs As Recordset)
  310. Dim rstCountry As Recordset
  311. Dim i As Long
  312. On Error Resume Next
  313.     Set m_db = db
  314.     Set mrstCustomers = rs.Clone
  315.     mvarBookmark = rs.Bookmark
  316.     mrstCustomers.Bookmark = mvarBookmark
  317.     Set rstCountry = m_db.OpenRecordset("SELECT DISTINCT Customers.Country FROM Customers ORDER BY Customers.Country", dbOpenSnapshot)
  318.     cboCountry.Clear
  319.     cboCountry.AddItem ""
  320.     Do Until rstCountry.EOF
  321.         cboCountry.AddItem rstCountry![Country]
  322.         rstCountry.MoveNext
  323.     Loop
  324.     txtField(fldCustomerID).Text = mrstCustomers![CustomerID]
  325.     txtField(fldCompanyName).Text = mrstCustomers![CompanyName]
  326.     txtField(fldContactName).Text = mrstCustomers![ContactName]
  327.     txtField(fldContactTitle).Text = mrstCustomers![ContactTitle]
  328.     txtField(fldAddress).Text = mrstCustomers![Address]
  329.     txtField(fldCity).Text = mrstCustomers![City]
  330.     txtField(fldRegion).Text = mrstCustomers![Region]
  331.     txtField(fldPostalCode).Text = mrstCustomers![PostalCode]
  332.     txtField(fldPhone).Text = mrstCustomers![Phone]
  333.     txtField(fldFax).Text = mrstCustomers![Fax]
  334.     cboCountry.Text = mrstCustomers![Country]
  335.     Caption = "Customers - " & mrstCustomers![CompanyName]
  336.     For i = 0 To UBound(m_DataChanged)
  337.         m_DataChanged(i) = False
  338.     Next
  339.         
  340.     Me.Show
  341. End Sub
  342. Public Sub NewRecord(db As Database, rs As Recordset)
  343. Dim rstCountry As Recordset
  344. Dim i As Long
  345. On Error Resume Next
  346.     Set m_db = db
  347.     Set mrstCustomers = rs.Clone
  348.     mbIsNew = True
  349.     mvarBookmark = Null
  350.     Set rstCountry = m_db.OpenRecordset("SELECT DISTINCT Customers.Country FROM Customers ORDER BY Customers.Country", dbOpenSnapshot)
  351.     cboCountry.Clear
  352.     cboCountry.AddItem ""
  353.     Do Until rstCountry.EOF
  354.         cboCountry.AddItem rstCountry![Country]
  355.         rstCountry.MoveNext
  356.     Loop
  357.     Caption = "Customers - New Customer"
  358.     Me.Show
  359. End Sub
  360. Private Sub cboCountry_Click()
  361.     m_DataChanged(fldCountry) = True
  362. End Sub
  363. Private Sub cboCountry_Change()
  364.     m_DataChanged(fldCountry) = True
  365. End Sub
  366. Private Sub cmdCancel_Click()
  367.     Unload Me
  368. End Sub
  369. Private Sub cmdOK_Click()
  370. On Error GoTo EH_cmdOK
  371. Dim bUpdate As Boolean
  372. Dim i As Integer
  373.     For i = 0 To UBound(m_DataChanged)
  374.         If m_DataChanged(i) Then bUpdate = True
  375.     Next
  376.     If bUpdate Then
  377.         If mbIsNew Then
  378.             mrstCustomers.AddNew
  379.         Else
  380.             mrstCustomers.Edit
  381.         End If
  382.         If m_DataChanged(fldCustomerID) Then mrstCustomers![CustomerID] = txtField(fldCustomerID)
  383.         If m_DataChanged(fldCompanyName) Then mrstCustomers![CompanyName] = txtField(fldCompanyName)
  384.         If m_DataChanged(fldContactName) Then mrstCustomers![ContactName] = txtField(fldContactName)
  385.         If m_DataChanged(fldContactTitle) Then mrstCustomers![ContactTitle] = txtField(fldContactTitle)
  386.         If m_DataChanged(fldAddress) Then mrstCustomers![Address] = txtField(fldAddress)
  387.         If m_DataChanged(fldCity) Then mrstCustomers![City] = txtField(fldCity)
  388.         If m_DataChanged(fldRegion) Then mrstCustomers![Region] = txtField(fldRegion)
  389.         If m_DataChanged(fldPostalCode) Then mrstCustomers![PostalCode] = txtField(fldPostalCode)
  390.         If m_DataChanged(fldPhone) Then mrstCustomers![Phone] = txtField(fldPhone)
  391.         If m_DataChanged(fldFax) Then mrstCustomers![Fax] = txtField(fldFax)
  392.         If m_DataChanged(fldCountry) Then mrstCustomers![Country] = cboCountry.Text
  393.         mrstCustomers.Update
  394.         Hide
  395.         frmMain.OnRecordUpdate CatalogCustomers, mvarBookmark
  396.     End If
  397.     Unload Me
  398.     Exit Sub
  399. EH_cmdOK:
  400.     MsgBox Err.Description
  401. End Sub
  402. Private Sub Form_Unload(Cancel As Integer)
  403.     frmMain.UnloadForm Key
  404. End Sub
  405. Private Sub txtField_Change(Index As Integer)
  406.     m_DataChanged(Index) = True
  407. End Sub
  408.