Documente Academic
Documente Profesional
Documente Cultură
Data-bound
Q4. Explain how BOF and EOF properties are set and how they might be used in a
project.( 6 mrks )
Ans:
1. Two handy properties of the record set are BOF (beginning of file) and EOF (end of file).
The BOF property is automatically set to true when the record pointer is before the first
record in the record set. This condition happens when first record is current and the user
choose MovePrevious. The BOF property is also true if the record set is empty
2. The EOF property is similar to BOF; it is true when the record pointer moves beyond the
last record in the record set and when the record set is empty.
3. When you are doing your own navigation in code, you need to check for BOF and EOF
so that run-time errors do not occur. If the user clicks MoveNext when on the last record,
what do you to do? Have the program cancel with a run time error? Display a message?
Wrap around the first record? Keep the record pointer to last record?
4. In the following example, we will wrap-around method. If the user clicks on the
MoveNext button from the end of the table, the first record becomes active record.
Private Sub cmdNext_Click()
Move to Next record
datBooks.Recordset.MoveNext
If datBooks.Recordset.EOF Then
datBooks.Recordset.MoveFirst
End If
End Sub
Q6. What are the steps needed to add a new record to database?( 4 mrks )
Ans:
1. When you want to add new record you have couple of choices. If you are using data
controls navigation buttons, you can allow Visual Basic to do the adds automatically. Set
the data controls EOF action property to 2 AddNew. When the user moves to end of
the file and clicks the arrow buttons, the Update method is automatically executed and
the new record is added.
2. You need a different approach when you use code to accomplish record navigation.
Assume that you have a command button to menu choice to add a new record. In the
click event for the command button use AddNew method:
3. datBooks.Recordset.AddNew
4. When this statement executes, all bound controls are cleared so that the user can enter
the data for the new record. After the data fields are entered, the new record must be
saved in the file. You can explicitly save it with an update method; or, it the user moves
to anther record, the update method is automatically executed.
5. You may want to use two buttons for adding a new record an Add button and s save
button. For the Add button, use an AddNew method; for the Save button, use the Update
method.
6. When adding new records, some conditions can cause errors to occur.
7. For example, if the key field is blank on a New record, a run time error holts the program
execution.
Q7. What are the steps needed to delete a record from database?( 4 mrks )
Ans:
1. The delete method deletes current record. The user should display the record to delete
and click a Delete command button or menu choice.
2. When a record is deleted, the current record is no longer valid. Therefore, a delete
method must be followed by MoveNext method.
With datBooks.Recordset
.Delete
.MoveNext
End With
3. But what if the record being deleted is the last record in the table?
4. Remember that if the navigation buttons are used to navigate, moving beyond EOF just
resets the current record to the last record.
Q8. What steps are needed to change the data in a database?( 4 mrks )
Ans:
The record set object has an Update method, which you can use to save any changes in the
data. Most of the time, updating is automatically executes the Update method any time the user
clicks one of the navigation buttons or one the Move methods executes.