Databases - Using DAO
You can move through a Recordset in code using the MoveFirst, MovePrevious, MoveNext and MoveLast methods. If you are at the first record, and you use the MovePrevious method, the BOF property will be set to true, and there will be no current record. If you cal it again, an error occurs. A similar thing happens with MoveNext.
Before you move to a different record, you should make sure that you invoke the Update method to save any changes to the current record.
When you are working with dynaset or snapshot type recordsets, the data is not fully populated when the recordset is created. To populate the recordset, execute MoveLast to move to the end of the data. You should not do this too often, as it has an impact on the application's performance. To improve this problem, you could call the MoveLast method with the dbRunAsync parameter to call it asynchrous. This means that the call returns immediately, and the database does the work in the background. To see if the call is completed, check the StillExecuting property, and to stop it, call the Cancel method.
To move more than one record at a time, use the Move method. This moves forwards or backwards a number of records relative to the current record, depending on the parameter. To move to a set record, set the AbsolutePosition property.
To find certain criteria within the recordset, use the FindFirst, FindLast, FindNext and FindPrevious methods. These all do a search through the recordset, starting either and the beginning (FindFirst), end (FindLast) or at the current record. FindLast and FindPrevious both search backwards through the data, and FindFirst and FindNext search forwards. The search criteria are similar to what you would use in the SELECT statement found above, and more information can be found in the help file. However, these methods only work for dynaset and snapshot type recordsets. If you have a table type recordset, use the seek method. You may find that for large recordsets, these are quite slow, and you may have to revert to a SQL SELECT statement to speed things up.
This is extremely simple to do: just use the AddNew method. This adds a new record to the end, and selects it as the current record.
Accessing Text Databases
If you do not need all the features of MS Access databases, then a simple text database
may be all you need. This will probably be quick than code created by hand, and will save
lots of extra coding.
The essential part of text databases is the schema.ini file. All you need to know is in the help file, as usual, under "Initializing the Text Data Source Driver". In here, it shows you how to create the necessary information in the schema.ini file to load the text file. This file defines the fields and delimiters between them, so that the database engine can load the text file. Then you can access and change it as you would any other recordset.
That's about it for coding databases with DAO. Some of the things in this article refer only to MS Jet data sources, so check that the data source that you are using supports the methods before you start to use them.
Page 3 of 3