To open a table in the current database, use the following command:
Set mytb = ActiveDatabase.Open("mytable")
The variable mytb now allows access to the table object. Here are the most important methods and properties of the table object:
Activate |
Make the table the current one (bring it to the front). |
Fields |
The collection of fields – field information and data. |
MoveFirst |
Go to the first record. |
MoveNext |
Go to the next record. |
MovePrev |
Go to the previous record. |
MoveLast |
Go to the last record. |
Close |
Close the table. |
EditRecord |
Allow changes to be written back to the current record. Puts the table into an "Edit" state. |
AddNewRecord |
Allow changes to be saves as a new record. Puts the table into an "Append" state. |
UpdateRecord |
Write any pending to changes to the table and turn off Edit or Append state. |
Here's how to move open and move around the table:
Set mytb = ActiveDatabase.Open("mytable")
mytb.MoveFirst
MsgBox "First Record"
mytb.MoveNext
MsgBox "Second Record"
.....and so on.
Instead of supplying a specific name for the table, it's sometimes useful to work with the current table (which could be any table). Here's some code that does the same as above:
Set mytb = ActiveDataObject
mytb.MoveFirst
etc.
See: Working with fields for details on how to write changes to a table.