Working with fields

The Fields collection contains the all the fields for a table. An individual field has the following properties:

Value

Contents of the field.

Name

Name of the field.

For example, for quick look at the contents of record 1 in a table:

Set mytb = ActiveDatabase.Open("mytable")

mytb.MoveFirst

s = ""

For Each fld In mytb.Fields

s = s & fld.Name & ": " & fld.Value & vbCr 

Next

MsgBox "The first record looks like this: " & vbCr & vbCr & s

To update a record, you should really know a little about the type of fields you are using. For example, updating two fields, one called email and the other tel:

With mytb

.EditRecord 

.Fields("email").Value = "test@ability.com" 

.Fields("tel").Value = "01234 5678" 

.UpdateRecord 

End With

Note that you always have to set the table into an "edit" state with the EditRecord command and complete the edit with UpdateRecord.

Adding a new record would be very similar:

With mytb

.AddNewRecord 

.Fields("email").Value = "test@ability.com" 

.Fields("tel").Value = "01234 5678" 

.UpdateRecord 

End With