Data Control

The BOF / EOF Action

The BOFAction and EOFAction properties allow you to control what happens when the control reaches the BOF (beginning of file) or the EOF (end of file).

Data1.BOFAction = integer

For the BOFAction property, the settings for integer are:

Setting Value Description
vbBOFActionMoveFirst 0 MoveFirst (Default): Keeps the first record as the current record.
vbBOFActionBOF 1 BOF: Moving past the beginning of a Recordset triggers the Data control Validate event on the first record, followed by a Reposition event on the invalid (BOF) record. At this point, the Move Previous button on the Data control is disabled.

Data1.EOFAction = integer

For the EOFAction property, the settings for integer are:

Setting Value Description
vbEOFActionMoveLast 0 MoveLast (Default): Keeps the last record as the current record.
vbEOFActionEOF 1 EOF: Moving past the end of a Recordset triggers the Data control's Validation event on the last record, followed by a Reposition event on the invalid (EOF) record. At this point, the MoveNext button on the Data control is disabled.
vbEOFActionAddNew 2 AddNew: Moving past the last record triggers the Data control's Validation event to occur on the current record, followed by an automatic AddNew, followed by a Reposition event on the new record.


If you set the EOFAction property to vbEOFActionAddNew, once the user reaches the end of the database (ie the last record), and attempts to view the non-existant next record, a new record is added. If you make changes to the new record and the user then moves to another record, the record is automatically appended to the Recordset. If you don't make changes to this new record, and the user moves to another record, the new record is discarded. 

When you use code to move between records the EOFAction property has no effect — it only takes effect when manipulating the Data control with the mouse.

In situations where there are no records in the database or after the last record has been deleted, using the vbEOFActionAddNew option for the EOFAction property greatly simplifies your code because a new record is always editable as the current record. If this option is not enabled, you are likely to trigger a "No current record" error.

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The generation of random numbers is too important to be left to chance.” - Robert R. Coveyou