home *** CD-ROM | disk | FTP | other *** search
- Option Explicit
-
- Sub cmdClose_Click ()
- Unload form2
- 'database is closed in the form unload event
- End Sub
-
- Sub cmdDelete_Click ()
- 'reminder:
- 'Global Const MB_YESNO = 4 ' Yes and No buttons
- 'Global Const IDYES = 6 ' Yes button pressed
- 'Global Const MB_DEFBUTTON2 = 256 ' Second button is default
-
- On Error GoTo cmddeleteERR
- Dim response As Integer
- response = MsgBox("Are sure you want to delete " & text1(0).Text & " ?", MB_YESNO + MB_DEFBUTTON2)
- If response = IDYES Then
- data1.Recordset.Delete
- 'refresh so our deleted record isn't still showing
- 'on screen
- data1.Refresh
- End If
-
- GoTo cmddeleteEND
- cmddeleteERR:
- showerror
- Resume cmddeleteEND
- cmddeleteEND:
-
- End Sub
-
- Sub cmdFind_Click ()
- On Error GoTo cmdfindERR
-
- Dim MyCriteria As String
- Dim sql As String
- 'construct a query to put the table in name order
- sql = "select * from [Place Names] order by Name"
- data1.RecordSource = sql
- 'refresh the datacontrol with the new order
- data1.Refresh
- 'get a name to look for
- MyCriteria = "Name >= '" & InputBox$("Name to find:") & "'"
- 'look for the name
- 'and find first matching record.
- data1.Recordset.FindFirst MyCriteria
- 'if not found, say so and point to the first valid record
- If data1.Recordset.NoMatch Then
- MsgBox "record not found"
- data1.Recordset.MoveFirst
- End If
-
- GoTo cmdfindEND
- cmdfindERR:
- showerror
- Resume cmdfindEND
- cmdfindEND:
-
- End Sub
-
- Sub cmdNew_Click ()
- On Error GoTo cmdnewERR
- data1.Recordset.AddNew
- text1(0).SetFocus
-
- GoTo cmdnewEND
- cmdnewERR:
- showerror
- Resume cmdnewEND
- cmdnewEND:
-
- End Sub
-
- Sub cmdUpdate_Click ()
- On Error GoTo cmdupdateERR
- data1.Recordset.Update
-
- GoTo cmdupdateEND
- cmdupdateERR:
- showerror
- Resume cmdupdateEND
- cmdupdateEND:
-
- End Sub
-
- Sub Form_Load ()
- On Error GoTo formERR
- Dim i As Integer
- 'set the database name to the data control
- data1.DatabaseName = ThePath + "USPLACE.MDB"
- 'point the data control to our table
- data1.RecordSource = "Place Names"
- 'open it up
- data1.Refresh
- 'just to show it can be done, get the labels
- 'and field names from the tabledefs object.
- 'you could also hard code them, or set them in
- 'the properties window
- For i = 0 To 4
- label1(i).Caption = data1.Database.TableDefs("Place Names").Fields(i + 1).Name
- text1(i).DataField = data1.Database.TableDefs("Place Names").Fields(i + 1).Name
- Next i
-
- 'note -- our table is now in primary key
- 'order at this point.
- 'The code in the find button event puts it in
- 'name order before executing the findfirst
-
- GoTo formEND
- formERR:
- showerror
- Resume formEND
- formEND:
-
- End Sub
-
- Sub Form_Unload (Cancel As Integer)
- On Error GoTo unloadERR
- data1.Recordset.Close
-
- GoTo unloadEND
- unloadERR:
- showerror
- Resume unloadEND
- unloadEND:
-
-
- End Sub
-
-