Access VBA Macro Programming

(Joao Candeias) #1

Main Properties, Methods, and Collections


This section details the main properties, methods, and collections you will use within the
Recordsetobject.

AddNew
TheAddnewmethod is used to add new records to theRecordsetobject. It has the effect of
creating a new blank record, which is then populated via the fields with data. TheUpdate
method is then used to write the data to the table.

RecSet.AddNew
RecSet![MyField1] = "MyData 1 "
RecSet![MyField2] = "MyData 2 "
RecSet.Update

Bear in mind that the data you enter into each field must satisfy the rules for that field. For
example, you cannot put text into a numeric field, and you must enter data for a required
field, otherwise an error message will be generated.

BOF
TheBOFproperty returns True or False as to whether the recordset is at the Beginning Of
File (BOF). If it is true, then it is at the first record.

MsgBox RecSet.BOF

Close
TheClosemethod closes the recordset and releases the underlying table:

RecSet.Close

It is important to do this at the end of your code because otherwise the underlying table
will show it as being still in use. This will mean that you will be unable to make any
structural changes to the table.
It is also a good idea to set theRecordsetobject to Nothing to release the memory. Some
Recordset objects can be very large and can become memory-hungry if not fully erased.

Set RecSet = Nothing

Delete
TheDeletemethod deletes the current record in the recordset:

RecSet.Delete

UnlikeAddNew, you do not need to use theUpdatemethod after the delete.

208 Microsoft Access 2010 VBA Macro Programming

Free download pdf