home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / code / database / dtadmo / form2.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-10-15  |  7.5 KB  |  268 lines

  1. VERSION 2.00
  2. Begin Form Form2 
  3.    Caption         =   "Form2"
  4.    ClientHeight    =   4260
  5.    ClientLeft      =   1110
  6.    ClientTop       =   1500
  7.    ClientWidth     =   7365
  8.    Height          =   4665
  9.    Left            =   1050
  10.    LinkTopic       =   "Form2"
  11.    ScaleHeight     =   4260
  12.    ScaleWidth      =   7365
  13.    Top             =   1155
  14.    Width           =   7485
  15.    Begin CommandButton cmdClose 
  16.       Caption         =   "Close"
  17.       Height          =   495
  18.       Left            =   120
  19.       TabIndex        =   14
  20.       Top             =   3480
  21.       Width           =   1455
  22.    End
  23.    Begin CommandButton cmdDelete 
  24.       Caption         =   "Delete"
  25.       Height          =   495
  26.       Left            =   6120
  27.       TabIndex        =   13
  28.       Top             =   3480
  29.       Width           =   1215
  30.    End
  31.    Begin CommandButton cmdUpdate 
  32.       Caption         =   "Update"
  33.       Height          =   495
  34.       Left            =   4440
  35.       TabIndex        =   12
  36.       Top             =   3480
  37.       Width           =   1215
  38.    End
  39.    Begin CommandButton cmdNew 
  40.       Caption         =   "New"
  41.       Height          =   495
  42.       Left            =   3120
  43.       TabIndex        =   11
  44.       Top             =   3480
  45.       Width           =   1215
  46.    End
  47.    Begin CommandButton cmdFind 
  48.       Caption         =   "Find"
  49.       Height          =   495
  50.       Left            =   1800
  51.       TabIndex        =   10
  52.       Top             =   3480
  53.       Width           =   1215
  54.    End
  55.    Begin TextBox Text1 
  56.       DataSource      =   "Data1"
  57.       Height          =   495
  58.       Index           =   4
  59.       Left            =   1800
  60.       TabIndex        =   4
  61.       Text            =   "Text1"
  62.       Top             =   2520
  63.       Width           =   1215
  64.    End
  65.    Begin TextBox Text1 
  66.       DataSource      =   "Data1"
  67.       Height          =   495
  68.       Index           =   3
  69.       Left            =   1800
  70.       TabIndex        =   3
  71.       Text            =   "Text1"
  72.       Top             =   1920
  73.       Width           =   1215
  74.    End
  75.    Begin TextBox Text1 
  76.       DataSource      =   "Data1"
  77.       Height          =   495
  78.       Index           =   2
  79.       Left            =   1800
  80.       TabIndex        =   2
  81.       Text            =   "Text1"
  82.       Top             =   1320
  83.       Width           =   1215
  84.    End
  85.    Begin TextBox Text1 
  86.       DataSource      =   "Data1"
  87.       Height          =   495
  88.       Index           =   1
  89.       Left            =   1800
  90.       TabIndex        =   1
  91.       Text            =   "Text1"
  92.       Top             =   720
  93.       Width           =   1215
  94.    End
  95.    Begin TextBox Text1 
  96.       DataSource      =   "Data1"
  97.       Height          =   495
  98.       Index           =   0
  99.       Left            =   1800
  100.       TabIndex        =   0
  101.       Text            =   "Text1"
  102.       Top             =   120
  103.       Width           =   5295
  104.    End
  105.    Begin Data Data1 
  106.       Caption         =   "Data1"
  107.       Connect         =   ""
  108.       DatabaseName    =   ""
  109.       Exclusive       =   0   'False
  110.       Height          =   270
  111.       Left            =   1800
  112.       Options         =   0
  113.       ReadOnly        =   0   'False
  114.       RecordSource    =   ""
  115.       Top             =   3120
  116.       Width           =   3855
  117.    End
  118.    Begin Label Label1 
  119.       Caption         =   "Label1"
  120.       Height          =   495
  121.       Index           =   4
  122.       Left            =   480
  123.       TabIndex        =   9
  124.       Top             =   2520
  125.       Width           =   1215
  126.    End
  127.    Begin Label Label1 
  128.       Caption         =   "Label1"
  129.       Height          =   495
  130.       Index           =   3
  131.       Left            =   480
  132.       TabIndex        =   8
  133.       Top             =   1920
  134.       Width           =   1215
  135.    End
  136.    Begin Label Label1 
  137.       Caption         =   "Label1"
  138.       Height          =   495
  139.       Index           =   2
  140.       Left            =   480
  141.       TabIndex        =   7
  142.       Top             =   1320
  143.       Width           =   1215
  144.    End
  145.    Begin Label Label1 
  146.       Caption         =   "Label1"
  147.       Height          =   495
  148.       Index           =   1
  149.       Left            =   480
  150.       TabIndex        =   6
  151.       Top             =   720
  152.       Width           =   1215
  153.    End
  154.    Begin Label Label1 
  155.       Caption         =   "Label1"
  156.       Height          =   495
  157.       Index           =   0
  158.       Left            =   480
  159.       TabIndex        =   5
  160.       Top             =   120
  161.       Width           =   1215
  162.    End
  163. Option Explicit
  164. Sub cmdClose_Click ()
  165.     Unload form2
  166.     'database is closed in the form unload event
  167. End Sub
  168. Sub cmdDelete_Click ()
  169. 'reminder:
  170. 'Global Const MB_YESNO = 4              ' Yes and No buttons
  171. 'Global Const IDYES = 6                 ' Yes button pressed
  172. 'Global Const MB_DEFBUTTON2 = 256       ' Second button is default
  173.     On Error GoTo cmddeleteERR
  174.     Dim response As Integer
  175.     response = MsgBox("Are sure you want to delete " & text1(0).Text & " ?", MB_YESNO + MB_DEFBUTTON2)
  176.     If response = IDYES Then
  177.     data1.Recordset.Delete
  178.     'refresh so our deleted record isn't still showing
  179.     'on screen
  180.     data1.Refresh
  181.     End If
  182. GoTo cmddeleteEND
  183. cmddeleteERR:
  184.     showerror
  185.     Resume cmddeleteEND
  186. cmddeleteEND:
  187. End Sub
  188. Sub cmdFind_Click ()
  189.     On Error GoTo cmdfindERR
  190.     Dim MyCriteria As String
  191.     Dim sql As String
  192.     'construct a query to put the table in name order
  193.     sql = "select * from [Place Names] order by Name"
  194.     data1.RecordSource = sql
  195.     'refresh the datacontrol with the new order
  196.     data1.Refresh
  197.     'get a name to look for
  198.     MyCriteria = "Name >= '" & InputBox$("Name to find:") & "'"
  199.     'look for the name
  200.     'and find first matching record.
  201.     data1.Recordset.FindFirst MyCriteria
  202.     'if not found, say so and point to the first valid record
  203.     If data1.Recordset.NoMatch Then
  204.     MsgBox "record not found"
  205.     data1.Recordset.MoveFirst
  206.     End If
  207. GoTo cmdfindEND
  208. cmdfindERR:
  209.     showerror
  210.     Resume cmdfindEND
  211. cmdfindEND:
  212. End Sub
  213. Sub cmdNew_Click ()
  214.     On Error GoTo cmdnewERR
  215.     data1.Recordset.AddNew
  216.     text1(0).SetFocus
  217. GoTo cmdnewEND
  218. cmdnewERR:
  219.     showerror
  220.     Resume cmdnewEND
  221. cmdnewEND:
  222. End Sub
  223. Sub cmdUpdate_Click ()
  224.     On Error GoTo cmdupdateERR
  225.     data1.Recordset.Update
  226. GoTo cmdupdateEND
  227. cmdupdateERR:
  228.     showerror
  229.     Resume cmdupdateEND
  230. cmdupdateEND:
  231. End Sub
  232. Sub Form_Load ()
  233.     On Error GoTo formERR
  234.     Dim i As Integer
  235.     'set the database name to the data control
  236.     data1.DatabaseName = ThePath + "USPLACE.MDB"
  237.     'point the data control to our table
  238.     data1.RecordSource = "Place Names"
  239.     'open it up
  240.     data1.Refresh
  241.     'just to show it can be done, get the labels
  242.     'and field names from the tabledefs object.
  243.     'you could also hard code them, or set them in
  244.     'the properties window
  245.     For i = 0 To 4
  246.     label1(i).Caption = data1.Database.TableDefs("Place Names").Fields(i + 1).Name
  247.     text1(i).DataField = data1.Database.TableDefs("Place Names").Fields(i + 1).Name
  248.     Next i
  249.     'note -- our table is now in primary key
  250.     'order at this point.
  251.     'The code in the find button event puts it in
  252.     'name order before executing the findfirst
  253. GoTo formEND
  254. formERR:
  255.     showerror
  256.     Resume formEND
  257. formEND:
  258. End Sub
  259. Sub Form_Unload (Cancel As Integer)
  260.     On Error GoTo unloadERR
  261.     data1.Recordset.Close
  262. GoTo unloadEND
  263. unloadERR:
  264.     showerror
  265.     Resume unloadEND
  266. unloadEND:
  267. End Sub
  268.