Access VBA Macro Programming

(Joao Candeias) #1

Edit


TheEditmethod is used to edit records in theRecordsetobject. It allows changes to be made
to data in specified fields. TheUpdatemethod is then used to write the data to the table.


RecSet.Edit
RecSet![MyField1] = "MyNewData 1 "
RecSet![MyField2] = "MyNewData 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.


EOF


TheEOFproperty returns True or False as to whether the recordset is at the End Of File
(EOF). If it is true, then it is at the last record.


MsgBox RecSet.EOF


Fields


Fieldsis a collection representing all the fields within theRecordsetobject. It is useful if
you need to obtain details on the field before any updating takes place.


With RecSet.Fields( 0 )
MsgBox .Name
MsgBox .Type
MsgBox .Value
MsgBox .Size
End With


This code provides details of the first field in the record. Notice the index starts at 0.

FindFirst


TheFindFirstmethod uses a specified criterion to find the first instance of a record within
the recordset. The recordset must be opened as a snapshot or dynaset (which is updatable) for
the method to work:


Dim RecSet As Recordset
Set RecSet = CurrentDb.OpenRecordset("MyTable", dbOpenDynaset)
RecSet.FindFirst ("MyField='Data'")
MsgBox RecSet!MyField
RecSet.close
Set RecSet=Nothing


This code will move to the first record where the field MyField contains the value Data.

Chapter 15: The Main Objects 209

Free download pdf