home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD112641132000.psc / Form1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2000-11-03  |  13.6 KB  |  433 lines

  1. VERSION 5.00
  2. Begin VB.Form Main 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Database"
  5.    ClientHeight    =   3225
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   5700
  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            =   "Form1.frx":0000
  19.    KeyPreview      =   -1  'True
  20.    LinkTopic       =   "Form1"
  21.    MaxButton       =   0   'False
  22.    ScaleHeight     =   3225
  23.    ScaleWidth      =   5700
  24.    StartUpPosition =   2  'CenterScreen
  25.    Begin VB.Data BDD 
  26.       Connect         =   "Access"
  27.       DatabaseName    =   ""
  28.       DefaultCursorType=   0  'DefaultCursor
  29.       DefaultType     =   2  'UseODBC
  30.       Exclusive       =   0   'False
  31.       Height          =   345
  32.       Left            =   3195
  33.       Options         =   0
  34.       ReadOnly        =   0   'False
  35.       RecordsetType   =   1  'Dynaset
  36.       RecordSource    =   "Customer"
  37.       Top             =   15
  38.       Visible         =   0   'False
  39.       Width           =   2175
  40.    End
  41.    Begin VB.CommandButton BtnClose 
  42.       Caption         =   "Close"
  43.       Height          =   375
  44.       Left            =   4365
  45.       TabIndex        =   10
  46.       Top             =   2745
  47.       Width           =   1200
  48.    End
  49.    Begin VB.CommandButton BtnLast 
  50.       Height          =   375
  51.       Left            =   1230
  52.       Picture         =   "Form1.frx":014A
  53.       Style           =   1  'Graphical
  54.       TabIndex        =   7
  55.       TabStop         =   0   'False
  56.       Top             =   2745
  57.       Width           =   395
  58.    End
  59.    Begin VB.CommandButton BtnNext 
  60.       Height          =   375
  61.       Left            =   855
  62.       Picture         =   "Form1.frx":02EC
  63.       Style           =   1  'Graphical
  64.       TabIndex        =   6
  65.       TabStop         =   0   'False
  66.       Top             =   2745
  67.       Width           =   375
  68.    End
  69.    Begin VB.CommandButton BtnPrevious 
  70.       Height          =   375
  71.       Left            =   480
  72.       Picture         =   "Form1.frx":048E
  73.       Style           =   1  'Graphical
  74.       TabIndex        =   5
  75.       TabStop         =   0   'False
  76.       Top             =   2745
  77.       Width           =   375
  78.    End
  79.    Begin VB.CommandButton BtnFirst 
  80.       Height          =   375
  81.       Left            =   105
  82.       Picture         =   "Form1.frx":0630
  83.       Style           =   1  'Graphical
  84.       TabIndex        =   4
  85.       TabStop         =   0   'False
  86.       Top             =   2745
  87.       Width           =   375
  88.    End
  89.    Begin VB.Frame FrmCustomer 
  90.       Caption         =   "Current Record"
  91.       BeginProperty Font 
  92.          Name            =   "Tahoma"
  93.          Size            =   8.25
  94.          Charset         =   0
  95.          Weight          =   700
  96.          Underline       =   0   'False
  97.          Italic          =   0   'False
  98.          Strikethrough   =   0   'False
  99.       EndProperty
  100.       Height          =   1560
  101.       Left            =   120
  102.       TabIndex        =   13
  103.       Top             =   1020
  104.       Width           =   5445
  105.       Begin VB.TextBox TBCode 
  106.          BackColor       =   &H00E0E0E0&
  107.          DataField       =   "Code"
  108.          DataSource      =   "BDD"
  109.          Height          =   315
  110.          Left            =   3480
  111.          TabIndex        =   17
  112.          Top             =   270
  113.          Visible         =   0   'False
  114.          Width           =   1740
  115.       End
  116.       Begin VB.TextBox TBSociety 
  117.          DataField       =   "Society"
  118.          DataSource      =   "BDD"
  119.          Height          =   315
  120.          Left            =   1275
  121.          TabIndex        =   3
  122.          Top             =   1050
  123.          Width           =   3960
  124.       End
  125.       Begin VB.TextBox TBName 
  126.          DataField       =   "Name"
  127.          DataSource      =   "BDD"
  128.          Height          =   315
  129.          Left            =   1275
  130.          TabIndex        =   2
  131.          Top             =   660
  132.          Width           =   3960
  133.       End
  134.       Begin VB.TextBox TBCodeTemp 
  135.          Height          =   315
  136.          Left            =   1290
  137.          TabIndex        =   1
  138.          Top             =   270
  139.          Width           =   1740
  140.       End
  141.       Begin VB.Label Label3 
  142.          Alignment       =   1  'Right Justify
  143.          Caption         =   "Society"
  144.          Height          =   255
  145.          Left            =   210
  146.          TabIndex        =   16
  147.          Top             =   1065
  148.          Width           =   930
  149.       End
  150.       Begin VB.Label Label1 
  151.          Alignment       =   1  'Right Justify
  152.          Caption         =   "Code"
  153.          Height          =   255
  154.          Left            =   210
  155.          TabIndex        =   15
  156.          Top             =   300
  157.          Width           =   930
  158.       End
  159.       Begin VB.Label Label2 
  160.          Alignment       =   1  'Right Justify
  161.          Caption         =   "Name"
  162.          Height          =   255
  163.          Left            =   210
  164.          TabIndex        =   14
  165.          Top             =   675
  166.          Width           =   930
  167.       End
  168.    End
  169.    Begin VB.CommandButton BtnNew 
  170.       Caption         =   "New (F2)"
  171.       Height          =   375
  172.       Left            =   1710
  173.       TabIndex        =   8
  174.       Top             =   2745
  175.       Width           =   1290
  176.    End
  177.    Begin VB.CommandButton BtnDelete 
  178.       Caption         =   "Delete (F5)"
  179.       Height          =   375
  180.       Left            =   3000
  181.       Style           =   1  'Graphical
  182.       TabIndex        =   9
  183.       Top             =   2745
  184.       Width           =   1290
  185.    End
  186.    Begin VB.Frame Frame2 
  187.       Caption         =   "Find Item"
  188.       BeginProperty Font 
  189.          Name            =   "Tahoma"
  190.          Size            =   8.25
  191.          Charset         =   0
  192.          Weight          =   700
  193.          Underline       =   0   'False
  194.          Italic          =   0   'False
  195.          Strikethrough   =   0   'False
  196.       EndProperty
  197.       Height          =   795
  198.       Left            =   105
  199.       TabIndex        =   11
  200.       Top             =   120
  201.       Width           =   5445
  202.       Begin VB.TextBox TBValue 
  203.          BackColor       =   &H00E4FFFF&
  204.          Height          =   315
  205.          Left            =   1275
  206.          TabIndex        =   0
  207.          Top             =   285
  208.          Width           =   3960
  209.       End
  210.       Begin VB.Label Label5 
  211.          Alignment       =   1  'Right Justify
  212.          Caption         =   "Find String"
  213.          Height          =   255
  214.          Left            =   210
  215.          TabIndex        =   12
  216.          Top             =   300
  217.          Width           =   930
  218.       End
  219.    End
  220.    Begin VB.Label Label4 
  221.       Caption         =   "Label4"
  222.       Height          =   225
  223.       Left            =   3795
  224.       TabIndex        =   18
  225.       Top             =   1005
  226.       Width           =   1710
  227.    End
  228. Attribute VB_Name = "Main"
  229. Attribute VB_GlobalNameSpace = False
  230. Attribute VB_Creatable = False
  231. Attribute VB_PredeclaredId = True
  232. Attribute VB_Exposed = False
  233. Dim OldCode As String
  234. Private Sub BDD_Reposition()
  235.     'Reminder current code
  236.     OldCode = TBCode
  237.     TBCodeTemp = TBCode
  238.     'Refresh position in database
  239.     Main.Caption = "Database" + " [" + CStr(BDD.Recordset.AbsolutePosition + 1) + " of " + CStr(Get_Number_Of_Record("Customer")) + "]"
  240. End Sub
  241. Private Sub BtnClose_Click()
  242.     Unload Me
  243.     End
  244. End Sub
  245. Private Sub BtnDelete_Click()
  246.     Dim Code As String
  247.     Dim NotDeleted As Boolean
  248.     'Keep current Code value
  249.     Code = TBCode
  250.     NotDeleted = False
  251.     'If Code is not null
  252.     If TBCode <> "" Then
  253.         'Save database to prevent error
  254.         BDD.Refresh
  255.         
  256.         'Find record to be delete
  257.         Find_Item "Code", Code
  258.         
  259.         'Confirm deletion
  260.         If vbYes = MsgBox("Are you sure to delete this record?", vbQuestion + vbYesNo, "Attention") Then
  261.             'Delete record
  262.             BDD.Recordset.Delete
  263.             BDD.Refresh
  264.         Else
  265.             NotDeleted = True
  266.         End If
  267.     End If
  268.     'If deleting has not been aborted
  269.     If NotDeleted = False Then
  270.         'If the database if not empty
  271.         If Not BDD.Recordset.EOF And Not BDD.Recordset.BOF Then
  272.             'Go to first record
  273.             BDD.Recordset.MoveFirst
  274.         Else
  275.             'Add a new record
  276.             BDD.Recordset.AddNew
  277.         End If
  278.         Manage_Records_Buttons BtnFirst, BtnPrevious, BtnNext, BtnLast, BDD
  279.     End If
  280. End Sub
  281. Private Sub BtnFirst_Click()
  282.     BDD.Recordset.MoveFirst
  283.     Manage_Records_Buttons BtnFirst, BtnPrevious, BtnNext, BtnLast, BDD
  284. End Sub
  285. Private Sub BtnLast_Click()
  286.     BDD.Recordset.MoveLast
  287.     Manage_Records_Buttons BtnFirst, BtnPrevious, BtnNext, BtnLast, BDD
  288. End Sub
  289. Private Sub BtnNew_Click()
  290.     'Save current database
  291.     BDD.Refresh
  292.     'Add the new record
  293.     BDD.Recordset.AddNew
  294.     'Disable all records buttons
  295.     BtnFirst.Enabled = False
  296.     BtnPrevious.Enabled = False
  297.     BtnNext.Enabled = False
  298.     BtnLast.Enabled = False
  299.     'Focus on the database primary key
  300.     TBCodeTemp.SetFocus
  301. End Sub
  302. Private Sub BtnNext_Click()
  303.     BDD.Recordset.MoveNext
  304.     Manage_Records_Buttons BtnFirst, BtnPrevious, BtnNext, BtnLast, BDD
  305. End Sub
  306. Private Sub BtnPrevious_Click()
  307.     BDD.Recordset.MovePrevious
  308.     Manage_Records_Buttons BtnFirst, BtnPrevious, BtnNext, BtnLast, BDD
  309. End Sub
  310. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  311.     Select Case KeyCode
  312.         Case vbKeyPageUp
  313.             KeyCode = 0
  314.             If BtnPrevious.Enabled = True Then Call BtnPrevious_Click
  315.         Case vbKeyPageDown
  316.             KeyCode = 0
  317.             If BtnNext.Enabled = True Then Call BtnNext_Click
  318.         Case vbKeyF2
  319.             KeyCode = 0
  320.             Call BtnNew_Click
  321.         Case vbKeyF5
  322.             KeyCode = 0
  323.             Call BtnDelete_Click
  324.     End Select
  325. End Sub
  326. Private Sub Form_Load()
  327.     If FileExists(App.Path + "\BDD.MDB") Then
  328.         BDD.DatabaseName = App.Path + "\BDD.MDB"
  329.         BDD.EOFAction = vbEOFActionAddNew
  330.         BDD.Refresh
  331.         If BDD.Recordset.EOF Or BDD.Recordset.BOF Then
  332.             BDD.Recordset.AddNew
  333.         End If
  334.         CBCriteria = "Contains"
  335.         Manage_Records_Buttons BtnFirst, BtnPrevious, BtnNext, BtnLast, BDD
  336.     Else
  337.         MsgBox "Can't find BDD.MDB in folder.", vbCritical, "Error"
  338.         Call BtnClose_Click
  339.     End If
  340. End Sub
  341. Private Sub TBCodeTemp_GotFocus()
  342.     Select_All TBCodeTemp
  343. End Sub
  344. Private Sub TBCodeTemp_KeyPress(KeyAscii As Integer)
  345.     UCaseMask KeyAscii
  346.     Max_Length TBCodeTemp, KeyAscii, 6
  347. End Sub
  348. Private Sub TBCodeTemp_Validate(Cancel As Boolean)
  349.     Dim Code As String
  350.     Code = TBCodeTemp
  351.     'If Code already exist
  352.     If Exists_Record("Customer", "Code", TBCodeTemp) And Code <> OldCode Then
  353.         If All_Empty Then
  354.             BDD.Recordset.CancelUpdate
  355.         End If
  356.         Find_Item "Code", Code
  357.     Else
  358.         If Code <> OldCode Then
  359.             TBCode = TBCodeTemp
  360.             BDD.Refresh
  361.             Find_Item "Code", Code
  362.         End If
  363.     End If
  364.     OldCode = TBCode
  365. End Sub
  366. Private Sub TBName_GotFocus()
  367.     Select_All TBName
  368. End Sub
  369. Private Sub TBName_KeyPress(KeyAscii As Integer)
  370.     Validate_Key_Not_Null KeyAscii
  371.     Max_Length TBName, KeyAscii, 50
  372. End Sub
  373. Private Sub TBSociety_GotFocus()
  374.     Select_All TBSociety
  375. End Sub
  376. Private Sub TBSociety_KeyPress(KeyAscii As Integer)
  377.     Validate_Key_Not_Null KeyAscii
  378.     Max_Length TBSociety, KeyAscii, 50
  379. End Sub
  380. Private Sub TBValue_GotFocus()
  381.     Select_All TBValue
  382. End Sub
  383. Private Sub TBValue_KeyPress(KeyAscii As Integer)
  384.     Max_Length TBValue, KeyAscii, 100
  385. End Sub
  386. Private Sub TBValue_Validate(Cancel As Boolean)
  387.     If TBValue <> "" Then
  388.         
  389.         'Find string in Code field
  390.         BDD.Recordset.FindFirst "Code" + " LIKE ""*" + TBValue + "*"""
  391.         'If no match
  392.         If BDD.Recordset.NoMatch Then
  393.             'Find string in Name field
  394.             BDD.Recordset.FindFirst "Name" + " LIKE ""*" + TBValue + "*"""
  395.         End If
  396.         'If no match
  397.         If BDD.Recordset.NoMatch Then
  398.             'Find string in Society field
  399.             BDD.Recordset.FindFirst "Society" + " LIKE ""*" + TBValue + "*"""
  400.         End If
  401.         'If no match
  402.         If BDD.Recordset.NoMatch Then
  403.             MsgBox "No record were found.", vbInformation, "Searching"
  404.         End If
  405.         
  406.         Manage_Records_Buttons BtnFirst, BtnPrevious, BtnNext, BtnLast, BDD
  407.         
  408.     End If
  409. End Sub
  410. 'If all fields are empty
  411. Function All_Empty() As Boolean
  412.     If TBCode <> "" Or TBName <> "" Or TBSociety <> "" Then
  413.         All_Empty = False
  414.     Else
  415.         All_Empty = True
  416.     End If
  417. End Function
  418. 'Find a record
  419. Function Find_Item(Field As String, Code As String, Optional Criteria As String = "=")
  420.     If Not BDD.Recordset.EOF And Not BDD.Recordset.BOF Then
  421.         BDD.Recordset.FindFirst Field + Criteria + " """ + Code + """"
  422.         Manage_Records_Buttons BtnFirst, BtnPrevious, BtnNext, BtnLast, BDD
  423.     End If
  424. End Function
  425. 'Prevent enter informations before primary key
  426. Function Validate_Key_Not_Null(KeyAscii As Integer)
  427.     If All_Empty Then
  428.         KeyAscii = 0
  429.         MsgBox "You have to enter Code first.", vbInformation, "Error"
  430.         TBCodeTemp.SetFocus
  431.     End If
  432. End Function
  433.