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"
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Begin VB.Form addsupplier 
   BackColor       =   &H00C0C0FF&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Add New Supplier"
   ClientHeight    =   6960
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   7530
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   6960
   ScaleWidth      =   7530
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton Command3 
      Caption         =   "Generate Supplier Id"
      Height          =   375
      Left            =   4680
      TabIndex        =   16
      Top             =   240
      Width           =   2415
   End
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   330
      Left            =   7560
      Top             =   960
      Width           =   2055
      _ExtentX        =   3625
      _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    =   "region"
      Caption         =   "db_region"
      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 MSAdodcLib.Adodc d 
      Height          =   330
      Left            =   7560
      Top             =   360
      Width           =   2055
      _ExtentX        =   3625
      _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    =   "supplier"
      Caption         =   "db_supplier"
      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 VB.Frame Frame1 
      BackColor       =   &H00C0FFC0&
      Height          =   3015
      Left            =   120
      TabIndex        =   1
      Top             =   120
      Width           =   4455
      Begin VB.CommandButton Command2 
         Caption         =   "&Clear fields"
         Height          =   375
         Left            =   3000
         TabIndex        =   15
         Top             =   2520
         Width           =   1215
      End
      Begin VB.CommandButton Command1 
         Caption         =   "&Add"
         Height          =   375
         Left            =   1680
         TabIndex        =   14
         Top             =   2520
         Width           =   1215
      End
      Begin MSDataListLib.DataCombo dc_region 
         Bindings        =   "addsupplier.frx":0000
         DataField       =   "region"
         DataSource      =   "Adodc1"
         Height          =   315
         Left            =   1680
         TabIndex        =   13
         Top             =   2040
         Width           =   2535
         _ExtentX        =   4471
         _ExtentY        =   556
         _Version        =   393216
         ListField       =   "region"
         Text            =   ""
      End
      Begin VB.TextBox txt_sup_address 
         Height          =   285
         Left            =   1680
         TabIndex        =   6
         Top             =   1680
         Width           =   2535
      End
      Begin VB.TextBox txt_sup_email 
         Height          =   285
         Left            =   1680
         TabIndex        =   5
         Top             =   1320
         Width           =   2535
      End
      Begin VB.TextBox txt_sup_phone 
         Height          =   285
         Left            =   1680
         TabIndex        =   4
         Top             =   960
         Width           =   2535
      End
      Begin VB.TextBox txt_sup_name 
         Height          =   285
         Left            =   1680
         TabIndex        =   3
         Top             =   600
         Width           =   2535
      End
      Begin VB.TextBox txt_sup_id 
         BackColor       =   &H00FFFFC0&
         Height          =   285
         Left            =   1680
         Locked          =   -1  'True
         TabIndex        =   2
         Top             =   240
         Width           =   2535
      End
      Begin VB.Label Label6 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Region"
         Height          =   195
         Left            =   360
         TabIndex        =   12
         Top             =   2040
         Width           =   510
      End
      Begin VB.Label Label5 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Address"
         Height          =   195
         Left            =   360
         TabIndex        =   11
         Top             =   1680
         Width           =   570
      End
      Begin VB.Label Label4 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Email"
         Height          =   195
         Left            =   360
         TabIndex        =   10
         Top             =   1320
         Width           =   375
      End
      Begin VB.Label Label3 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Phone"
         Height          =   195
         Left            =   360
         TabIndex        =   9
         Top             =   960
         Width           =   465
      End
      Begin VB.Label Label2 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Supplier Name"
         Height          =   195
         Left            =   360
         TabIndex        =   8
         Top             =   600
         Width           =   1035
      End
      Begin VB.Label Label1 
         AutoSize        =   -1  'True
         BackColor       =   &H00C0FFC0&
         Caption         =   "Supplier Id"
         Height          =   195
         Left            =   360
         TabIndex        =   7
         Top             =   240
         Width           =   750
      End
   End
   Begin MSDataGridLib.DataGrid DataGrid1 
      Bindings        =   "addsupplier.frx":0015
      Height          =   3615
      Left            =   120
      TabIndex        =   0
      Top             =   3240
      Width           =   7335
      _ExtentX        =   12938
      _ExtentY        =   6376
      _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     =   6
      BeginProperty Column00 
         DataField       =   "sup_id"
         Caption         =   "sup_id"
         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       =   "sup_name"
         Caption         =   "sup_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       =   "sup_phone"
         Caption         =   "sup_phone"
         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       =   "sup_email"
         Caption         =   "sup_email"
         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       =   "sup_address"
         Caption         =   "sup_address"
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column05 
         DataField       =   "region_code"
         Caption         =   "region_code"
         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     =   750.047
         EndProperty
         BeginProperty Column01 
            ColumnWidth     =   1140.095
         EndProperty
         BeginProperty Column02 
            ColumnWidth     =   1110.047
         EndProperty
         BeginProperty Column03 
            ColumnWidth     =   1244.976
         EndProperty
         BeginProperty Column04 
            ColumnWidth     =   1739.906
         EndProperty
         BeginProperty Column05 
            ColumnWidth     =   945.071
         EndProperty
      EndProperty
   End
End
Attribute VB_Name = "addsupplier"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If txt_sup_id.Text = "" Or txt_sup_name.Text = "" Or txt_sup_phone.Text = "" Or txt_sup_email.Text = "" Or txt_sup_address.Text = "" Or dc_region.Text = "" Then
    MsgBox "Fields Empty"
    Exit Sub
End If
con.Open "DSN=sega"
Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset



rs.Open "select * from supplier where sup_id ='" & Trim(txt_sup_id.Text) & "'", con, adOpenStatic, adLockOptimistic
If rs.EOF Then
    rs.Close
    rs.Open "select * from supplier", con, adOpenStatic, adLockOptimistic
    rs.AddNew
    rs1.Open "select * from region where region = '" & dc_region.Text & "'", con, adOpenStatic, adLockOptimistic
    
    If rs1.EOF Then
    
        MsgBox "region name mismatch "
        rs1.Close
        con.Close
        Exit Sub
    Else
        rs!region_code = rs1!region_code
        rs1.Close
    End If


    rs!sup_id = Trim(txt_sup_id.Text)
    rs!sup_name = txt_sup_name.Text
    rs!sup_phone = Trim(txt_sup_phone.Text)
    rs!sup_email = Trim(txt_sup_email.Text)
    rs!sup_address = Trim(txt_sup_address.Text)
    'dc_region.Text = dc_region.Text

    rs.Update
    MsgBox "record added"
    rs.Close
Else

    MsgBox "region code already exists: "

End If

d.Refresh

con.Close

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End Sub

Private Sub Command2_Click()
txt_sup_id.Text = ""
txt_sup_name.Text = ""
txt_sup_phone.Text = ""
txt_sup_email.Text = ""
txt_sup_address.Text = ""
dc_region.Text = ""
   
End Sub

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

rs2.Open "select * from supplier order by sup_id", con, adOpenStatic, adLockOptimistic

If rs2.EOF Then
x = "S-1"
Else
rs2.MoveLast
a = rs2!sup_id
x = "S-" & Int(Mid(a, 3)) + 1
End If

txt_sup_id.Text = x
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
