movefirst returns last recordset

  • Thread starter Thread starter http
  • Start date Start date
H

http

The following code returns not the first, but the last record:

Set db = CurrentDb()
Set tblspec = db.OpenRecordset("tblPIDspec")
tblspec.MoveFirst
MsgBox tblspec("ID")

The MsgBox shows "10" because the Table includes 10 records.
How ist this possible?

thx.
Thomas
 
When you use a table as a recordset it is ordered by it's placement on
the hard-disk. It will be ordered based on whatever order it went
into the table. If you want it to be ordered by ID then set your
recordset to this:

Set tblspec = db.OpenRecordset("SELECT * FROM tblPIDspec ORDER BY ID")
 
Back
Top