home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / code / database / dtadmo / form2.txt < prev    next >
Encoding:
Text File  |  1995-02-27  |  3.0 KB  |  130 lines

  1. Option Explicit
  2.  
  3. Sub cmdClose_Click ()
  4.     Unload form2
  5.     'database is closed in the form unload event
  6. End Sub
  7.  
  8. Sub cmdDelete_Click ()
  9. 'reminder:
  10. 'Global Const MB_YESNO = 4              ' Yes and No buttons
  11. 'Global Const IDYES = 6                 ' Yes button pressed
  12. 'Global Const MB_DEFBUTTON2 = 256       ' Second button is default
  13.  
  14.     On Error GoTo cmddeleteERR
  15.     Dim response As Integer
  16.     response = MsgBox("Are sure you want to delete " & text1(0).Text & " ?", MB_YESNO + MB_DEFBUTTON2)
  17.     If response = IDYES Then
  18.     data1.Recordset.Delete
  19.     'refresh so our deleted record isn't still showing
  20.     'on screen
  21.     data1.Refresh
  22.     End If
  23.  
  24. GoTo cmddeleteEND
  25. cmddeleteERR:
  26.     showerror
  27.     Resume cmddeleteEND
  28. cmddeleteEND:
  29.  
  30. End Sub
  31.  
  32. Sub cmdFind_Click ()
  33.     On Error GoTo cmdfindERR
  34.  
  35.     Dim MyCriteria As String
  36.     Dim sql As String
  37.     'construct a query to put the table in name order
  38.     sql = "select * from [Place Names] order by Name"
  39.     data1.RecordSource = sql
  40.     'refresh the datacontrol with the new order
  41.     data1.Refresh
  42.     'get a name to look for
  43.     MyCriteria = "Name >= '" & InputBox$("Name to find:") & "'"
  44.     'look for the name
  45.     'and find first matching record.
  46.     data1.Recordset.FindFirst MyCriteria
  47.     'if not found, say so and point to the first valid record
  48.     If data1.Recordset.NoMatch Then
  49.     MsgBox "record not found"
  50.     data1.Recordset.MoveFirst
  51.     End If
  52.  
  53. GoTo cmdfindEND
  54. cmdfindERR:
  55.     showerror
  56.     Resume cmdfindEND
  57. cmdfindEND:
  58.  
  59. End Sub
  60.  
  61. Sub cmdNew_Click ()
  62.     On Error GoTo cmdnewERR
  63.     data1.Recordset.AddNew
  64.     text1(0).SetFocus
  65.  
  66. GoTo cmdnewEND
  67. cmdnewERR:
  68.     showerror
  69.     Resume cmdnewEND
  70. cmdnewEND:
  71.  
  72. End Sub
  73.  
  74. Sub cmdUpdate_Click ()
  75.     On Error GoTo cmdupdateERR
  76.     data1.Recordset.Update
  77.  
  78. GoTo cmdupdateEND
  79. cmdupdateERR:
  80.     showerror
  81.     Resume cmdupdateEND
  82. cmdupdateEND:
  83.  
  84. End Sub
  85.  
  86. Sub Form_Load ()
  87.     On Error GoTo formERR
  88.     Dim i As Integer
  89.     'set the database name to the data control
  90.     data1.DatabaseName = ThePath + "USPLACE.MDB"
  91.     'point the data control to our table
  92.     data1.RecordSource = "Place Names"
  93.     'open it up
  94.     data1.Refresh
  95.     'just to show it can be done, get the labels
  96.     'and field names from the tabledefs object.
  97.     'you could also hard code them, or set them in
  98.     'the properties window
  99.     For i = 0 To 4
  100.     label1(i).Caption = data1.Database.TableDefs("Place Names").Fields(i + 1).Name
  101.     text1(i).DataField = data1.Database.TableDefs("Place Names").Fields(i + 1).Name
  102.     Next i
  103.     
  104.     'note -- our table is now in primary key
  105.     'order at this point.
  106.     'The code in the find button event puts it in
  107.     'name order before executing the findfirst
  108.  
  109. GoTo formEND
  110. formERR:
  111.     showerror
  112.     Resume formEND
  113. formEND:
  114.  
  115. End Sub
  116.  
  117. Sub Form_Unload (Cancel As Integer)
  118.     On Error GoTo unloadERR
  119.     data1.Recordset.Close
  120.  
  121. GoTo unloadEND
  122. unloadERR:
  123.     showerror
  124.     Resume unloadEND
  125. unloadEND:
  126.  
  127.  
  128. End Sub
  129.  
  130.