Adding and deleting records
Up to this point, you have not written a single line of code. However, in order
to add some extra functionality, you will have to write a grand total of two
lines (well, 6 including the procedure names). First, add two command buttons
to the form:
|
Name
|
Caption
|
| cmdAdd |
&Add |
| cmdDelete |
&Delete |
In case your wondering, the ampersand (&) specifies the letter to be underlined
in the command button, and therefore allowing the user to press Alt+A for Add,
and Alt+D for delete if they wish. Then, double click the Add button to bring
up the code window. You can now enter the following code:
Private Sub cmdAdd_Click()
datTitles.Recordset.AddNew ' add a new record to the
table
End Sub
Private Sub cmdDelete_Click()
datTitles.Recordset.Delete ' delete current record
End Sub
After trying this, you will notice that when you delete an item you get some
blank fields. This is because there is no current record. In order to avoid
this, add
datTitles.Recordset.MoveNext
to the end of the cmdAdd_Click() Procedure