VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form addcustomer 
   BackColor       =   &H00C0C0FF&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Add New Customer"
   ClientHeight    =   7065
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   8970
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   7065
   ScaleWidth      =   8970
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton Command3 
      Caption         =   "Generate Customer No"
      Height          =   495
      Left            =   6120
      TabIndex        =   14
      Top             =   240
      Width           =   1935
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H00C0FFC0&
      Height          =   2775
      Left            =   120
      TabIndex        =   1
      Top             =   120
      Width           =   5775
      Begin VB.CommandButton Command2 
         Caption         =   "&Clear"
         Height          =   375
         Left            =   3840
         TabIndex        =   13
         Top             =   2160
         Width           =   1335
      End
      Begin VB.CommandButton Command1 
         Caption         =   "&Save"
         Height          =   375
         Left            =   2280
         TabIndex        =   12
         Top             =   2160
         Width           =   1335
      End
      Begin VB.TextBox txt_cust_email 
         Height          =   285
         Left            =   2040
         TabIndex        =   6
         Top             =   1680
         Width           =   3375
      End
      Begin VB.TextBox txt_cust_phone 
         Height          =   285
         Left            =   2040
         TabIndex        =   5
         Top             =   1320
         Width           =   3375
      End
      Begin VB.TextBox txt_cust_address 
         Height          =   285
         Left            =   2040
         TabIndex        =   4
         Top             =   960
         Width           =   3375
      End
      Begin VB.TextBox txt_cust_name 
         Height          =   285
         Left            =   2040
         TabIndex        =   3
         Top             =   600
         Width           =   3375
      End
      Begin VB.TextBox txt_cust_no 
         BackColor       =   &H00FFFFC0&
         Height          =   285
         Left            =   2040
         Locked          =   -1  'True
         TabIndex        =   2
         Top             =   240
         Width           =   3375
      End
      Begin VB.Label Label5 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Customer no"
         Height          =   195
         Left            =   360
         TabIndex        =   11
         Top             =   360
         Width           =   885
      End
      Begin VB.Label Label4 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Customer name"
         Height          =   195
         Left            =   360
         TabIndex        =   10
         Top             =   720
         Width           =   1095
      End
      Begin VB.Label Label3 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Customer address"
         Height          =   195
         Left            =   360
         TabIndex        =   9
         Top             =   1080
         Width           =   1260
      End
      Begin VB.Label Label2 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Customer phone"
         Height          =   195
         Left            =   360
         TabIndex        =   8
         Top             =   1440
         Width           =   1155
      End
      Begin VB.Label Label1 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Customer e-mail"
         Height          =   195
         Left            =   360
         TabIndex        =   7
         Top             =   1800
         Width           =   1110
      End
   End
   Begin MSAdodcLib.Adodc d 
      Height          =   330
      Left            =   4440
      Top             =   8760
      Width           =   2775
      _ExtentX        =   4895
      _ExtentY        =   582
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   2
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   3
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   "DSN=sega"
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   "sega"
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   "customer"
      Caption         =   "d"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin MSDataGridLib.DataGrid grd 
      Bindings        =   "addcustomer.frx":0000
      Height          =   3975
      Left            =   120
      TabIndex        =   0
      Top             =   3000
      Width           =   8775
      _ExtentX        =   15478
      _ExtentY        =   7011
      _Version        =   393216
      BackColor       =   12640511
      HeadLines       =   1
      RowHeight       =   15
      FormatLocked    =   -1  'True
      BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ColumnCount     =   5
      BeginProperty Column00 
         DataField       =   "cust_no"
         Caption         =   "cust_no"
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column01 
         DataField       =   "cust_name"
         Caption         =   "cust_name"
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column02 
         DataField       =   "cust_address"
         Caption         =   "cust_address"
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column03 
         DataField       =   "cust_phone"
         Caption         =   "cust_phone"
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column04 
         DataField       =   "cust_email"
         Caption         =   "cust_email"
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         BeginProperty Column00 
            ColumnWidth     =   1739.906
         EndProperty
         BeginProperty Column01 
            ColumnWidth     =   1739.906
         EndProperty
         BeginProperty Column02 
            ColumnWidth     =   1739.906
         EndProperty
         BeginProperty Column03 
            ColumnWidth     =   1140.095
         EndProperty
         BeginProperty Column04 
            ColumnWidth     =   1739.906
         EndProperty
      EndProperty
   End
End
Attribute VB_Name = "addcustomer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
If txt_cust_no.Text = "" Or txt_cust_name.Text = "" Or txt_cust_address.Text = "" Or txt_cust_phone.Text = "" Or txt_cust_email.Text = "" Then
    MsgBox "Fields Empty"
    Exit Sub
End If
con.Open "DSN=sega"
Dim rs As New ADODB.Recordset

rs.Open "select * from customer where cust_no ='" & Trim(txt_cust_no.Text) & "'", con, adOpenStatic, adLockOptimistic


If rs.EOF Then
    rs.Close


    rs.Open "select * from customer", con, adOpenStatic, adLockOptimistic
    'rs.MoveLast
    rs.AddNew

    rs!cust_no = Trim(txt_cust_no.Text)
    rs!cust_name = Trim(txt_cust_name.Text)
    rs!cust_address = Trim(txt_cust_address.Text)
    rs!cust_phone = Trim(txt_cust_phone.Text)
    rs!cust_email = Trim(txt_cust_email.Text)

    rs.Update

    MsgBox "record added"

    rs.Close
Else

    MsgBox "region code already exists: "

End If

d.Refresh
'grd.Refresh

con.Close
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End Sub

Private Sub Command2_Click()
clearfields
End Sub

Private Sub Command3_Click()
con.Open "DSN=sega"
Dim rs2 As New ADODB.Recordset
Dim cust
Dim a

rs2.Open "select * from customer order by cust_no", con, adOpenStatic, adLockOptimistic

If rs2.EOF Then
cust = "C-1"
Else
rs2.MoveLast
a = rs2!cust_no
cust = "c-" & Int(Mid(a, 3)) + 1
End If

txt_cust_no.Text = cust
con.Close
End Sub

Private Sub Form_Load()
mainform.Enabled = False
End Sub

Private Sub Form_Unload(Cancel As Integer)
'Exit_Click
    mainform.Enabled = True
End Sub
Private Sub clearfields()
    txt_cust_no = ""
    txt_cust_name = ""
    txt_cust_address = ""
    txt_cust_phone = ""
    txt_cust_email = ""
End Sub

