set recordset to first record

G

Guest

i new to write a number in each key field like '01' '02'...the code below
works but starts with the last record, it should start with the first record
in the temporary table.

Private Sub Command9_Click()
' write the line number for each po line
Dim count, cycles, linecount As String

cycles = 0 'how many loops
count = 0 ' number of records
linecount = "01" ' increment for line items

Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("LineItems", dbOpenTable)


rst.MoveLast
rst.MoveFirst
count = rst.recordcount


Do Until cycles = count

With rst
.AddNew
![LineNum] = linecount
.update
rst.MoveNext
linecount = linecount + 1
cycles = cycles + 1
End With

Loop

rst.close
 
R

RoyVidar

JP wrote in message
i new to write a number in each key field like '01' '02'...the code
below works but starts with the last record, it should start with
the first record in the temporary table.

Private Sub Command9_Click()
' write the line number for each po line
Dim count, cycles, linecount As String

cycles = 0 'how many loops
count = 0 ' number of records
linecount = "01" ' increment for line items

Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("LineItems", dbOpenTable)


rst.MoveLast
rst.MoveFirst
count = rst.recordcount


Do Until cycles = count

With rst
.AddNew
![LineNum] = linecount
.update
rst.MoveNext
linecount = linecount + 1
cycles = cycles + 1
End With

Loop

rst.close

Without specifying an order by clause, you have no way of knowing in
what order the returned has. If there's a field you can order by, try
that:

strSql = "select LineNum from LineItems order by somefield"
Set rst = dbs.OpenRecordset(strSql)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top