PDA

View Full Version : Why is my RecordSet not starting from record 1



bjay
09-01-2014, 11:35 AM
Hello all;

There may be a simple explanation to this, and hoping someone can help me.

I can't figure out why my Recordset start from record # 301 instead of # 1. Here's a screen shot:

12214
Table has 12,000 records and the first record has an ID of 1. So why is it start from the record 301? What am I doing wrong?

I thank you for your time.
BJ

jonh
09-02-2014, 01:34 AM
That's the order that the records were added.
If the field is indexed it will have a sort order but that sort is only used when opening tables and queries, etc.
To apply the index to a recordset get it from the tabledef. e.g.

Set td = db.TableDefs(tbl)
Dim idx As DAO.Index
For Each idx In td.Indexes
If idx.Primary Then
rs.Index = idx.Name
Exit For
End If
Next

Or just specify sort order when you create the rs

set rs = db.openrecordset("select * from strtable2 order by id asc")

bjay
09-02-2014, 07:35 AM
Hi Jonh, thank you so much for your reply. I think I will go with the query method for my purpose now. But thanks for clarifying why it wasn't doing what I expected.



Or just specify sort order when you create the rs

set rs = db.openrecordset("select * from strtable2 order by id asc")

BJ :hi:

ranman256
09-02-2014, 09:10 AM
you can skip the movefirst, movelast, statments.
it always starts at the 1st.

ranman256
09-10-2014, 05:22 AM
.remove this ;pls.