One thing that may confuse a lot of programmers, is that the first row of an Access table is NOT necessarily the first record.
For example consider the empty access table below: Lets say we copy the some data into the table: In the figure above the data being displayed in the first row of the table is the first record. The data being displayed in the second row is the second record, and so on ….
Lets say we change the order the data is being displayed in the table. Instead of showing data in ascending order, we change it to descending:
Right now the data in the first row of the table is associated with the last record.
How does this affect programmers? If in your program you assume the first row in the table is the first record, your program will run into logical errors.
For example in the figure above the value in the 3rd field of the first row is “Data 11”. The code below displays the value in the 3rd field of the first record:
Sub main() Dim objRecordset As ADODB.Recordset Set objRecordset = New ADODB.Recordset 'initated recordset obejct objRecordset.ActiveConnection = CurrentProject.Connection Call objRecordset.Open("MyTable1") objRecordset.MoveFirst MsgBox (objRecordset.Fields(2)) End Sub
As you can see the value in the 3rd field of the first record (“Data 1”) is not the same as the value in the 3rd field of the first row of the table (“Data 11”).
For more information about reading data from access tables using VBA please see the link below: