Private Sub cmdAdd_Click()
Dim iReply As Integer
'let the user add a new record
'confirm addition first
iReply = MsgBox("Do you want to add a new entry?", vbYesNo + vbQuestion, "Add Entry")
If iReply = vbNo Then
Exit Sub
End If
'disable the add, delete and edit buttons
cmdAdd.Enabled = False
cmdDelete.Enabled = False
cmdEdit.Enabled = False
'enable the cancel and save buttons
cmdCancel.Enabled = True
cmdSave.Enabled = True
'disable the navigation
DisableNavigation
'first unlock the text boxes
UnlockFields
'now add a new record to the table
Adodc1.Recordset.AddNew
'move to the owner text box for data input
txtOwner.SetFocus
End Sub
Private Sub cmdCancel_Click()
Dim iReply As Integer
Dim IRecordPos As Long
'confirm cancel before commiting
iReply = MsgBox("Cancel changes made?", vbYesNo + vbQuestion, "Cancel edits")
If iReply = vbNo Then
Exit Sub
End If
'update the table
Adodc1.Recordset.CancelUpdate
'enable add, delete and edit
cmdAdd.Enabled = True
cmdDelete.Enabled = True
cmdEdit.Enabled = True
'disable the save and cancel buttons, as we've finished with them
cmdSave.Enabled = False
cmdCancel.Enabled = False
'lock the textboxes
LockFields
'enable the navigation
EnableNavigation
'refresh
IRecordPos = Adodc1.Recordset.AbsolutePosition - 1
Adodc1.Refresh
Adodc1.Recordset.Move IRecordPosition, adBookmarkFirst
End Sub
Private Sub cmdDelete_Click()
Dim iReply As Integer
Dim ITitles As Long
'first confirm deletion
iReply = MsgBox("Delete selected entry?", vbYesNo + vbQuestion, "Delete Entry?")
If iReply = vbNo Then
Exit Sub
End If
'if we get here, delete the entry
Adodc1.Recordset.Delete
End Sub
Private Sub cmdEdit_Click()
'Disable the Add, Edit and Delete buttons
cmdAdd.Enabled = False
cmdEdit.Enabled = False
cmdDelete.Enabled = False
'enable save and cancel buttons
cmdSave.Enabled = True
cmdSave.Enabled = True
cmdCancel.Enabled = True
'disable the navigation
DisableNavigation
'unlock the owner, class name, number and entry number txtboxes
UnlockFields
'move to the owner txtbox
txtOwner.SetFocus
End Sub
Private Sub cmdFirst_Click()
'move to the first record in the table
Adodc1.Recordset.MoveFirst
End Sub
Private Sub cmdLast_Click()
'move to the last record
Adodc1.Recordset.MoveLast
End Sub
Private Sub cmdNext_Click()
'check for the end of the file first
If Adodc1.Recordset.EOF = True Then
Adodc1.Recordset.MoveFirst
Else
Adodc1.Recordset.MoveNext
End If
End Sub
Private Sub cmdPrevious_Click()
'check for beginning of the file
If Adodc1.Recordset.BOF = True Then
Adodc1.Recordset.MoveLast
Else
Adodc1.Recordset.MovePrevious
End If
End Sub
Public Sub DisableNavigation()
'to disable the navigation
cmdFirst.Enabled = False
cmdPrevious.Enabled = False
cmdNext.Enabled = False
cmdLast.Enabled = False
End Sub
Public Sub EnableNavigation()
cmdPrevious.Enabled = True
cmdNext.Enabled = True
cmdLast.Enabled = True
cmdFirst.Enabled = True
End Sub
Private Sub cmdSave_Click()
Dim iReply As Integer
'confirm updates before saving
iReply = MsgBox("Save changes made?", vbYesNo + vbQuestion, "save details")
If iReply = vbNo Then
Exit Sub
End If
'update the tables
Adodc1.Recordset.Update
'enable add, delete and edit
cmdAdd.Enabled = True
cmdEdit.Enabled = True
cmdDelete.Enabled = True
'disable cancel and save, cos we've finished with those
cmdCancel.Enabled = flase
cmdSave.Enabled = False
'lock the text boxes
LockFields
'enable navigation
EnableNavigation
End Sub
Private Sub Form_Load()
'disable the save details and cancel edit buttons
cmdSave.Enabled = False
cmdCancel.Enabled = False
LockFields
End Sub
Public Sub LockFields()
'lock all of the fields, so none of the information will be edited by accident
txtOwner.Locked = True
txtClass.Locked = True
txtClassNumber.Locked = True
txtClassName.Locked = True
txtEntryNumber.Locked = True
txtprizes.Locked = True
End Sub
Public Sub UnlockFields()
'unlock the fields
txtOwner.Locked = False
txtClass.Locked = False
txtClassNumber.Locked = False
txtClassName.Locked = False
txtEntryNumber.Locked = False
txtprizes.Locked = False
End Sub