Recordset?

  • Thread starter jbkirby via AccessMonster.com
  • Start date
J

jbkirby via AccessMonster.com

Let say i have this result of my query

FieldA FieldB FieldC
002 jerry kirby
004 balce fortes
021 cruz dela
041 dea bong
071 hey jam
090 bak dd
.....

and I want to get the value of the fourth record in FieldA, that is '041' to
be stored in a variable in a form. how do i employ this one?

This is what I want to do. But I can't find the right way to do it. Can
someone help me please.


Dim RS As Object
Set RS = CurrentDb().OpenRecordset("qryJBKirby")

iRecordCount = rs.recordcount
iSetCount = Int(iRecordCount / 16000)

a = 1

RS.MoveNext
a = a + 1
if a = 4 then (get value of fieldA)
end if
 
D

Douglas J. Steele

Sounds like an extremely unusual requirement that you need only a specific
row...


' You should always be explicit in your declarations
Dim RS As DAO.Recordset

Set RS = CurrentDb().OpenRecordset("qryJBKirby")
' The RecordCount property isn't guaranteed to be correct
' unless you move to the end of the recordset first.
RS.MoveLast
RS.MoveFirst
iRecordCount = RS.RecordCount
iSetCount = Int(iRecordCount / 16000)

a = 1
Do Until RS.EOF
RS.MoveNext
a = a + 1
if a = 4 then
MyValue = RS!FieldA
Exit Do
End If
Loop

' Cleanup after yourself
RS.Close
Set RS = Nothing


Alternatively, you could replace the Do loop with

RS.Move 4
MyValue = RS!FieldA
 
J

jbkirby via AccessMonster.com

It seem that if I use Rs.move 4, and access the record, it is actually the
fifth record. By the way, thank you. I got an idea.
Douglas said:
Sounds like an extremely unusual requirement that you need only a specific
row...

' You should always be explicit in your declarations
Dim RS As DAO.Recordset

Set RS = CurrentDb().OpenRecordset("qryJBKirby")
' The RecordCount property isn't guaranteed to be correct
' unless you move to the end of the recordset first.
RS.MoveLast
RS.MoveFirst
iRecordCount = RS.RecordCount
iSetCount = Int(iRecordCount / 16000)

a = 1
Do Until RS.EOF
RS.MoveNext
a = a + 1
if a = 4 then
MyValue = RS!FieldA
Exit Do
End If
Loop

' Cleanup after yourself
RS.Close
Set RS = Nothing

Alternatively, you could replace the Do loop with

RS.Move 4
MyValue = RS!FieldA
Let say i have this result of my query
[quoted text clipped - 26 lines]
if a = 4 then (get value of fieldA)
end if
 
D

Douglas J. Steele

jbkirby via AccessMonster.com said:
It seem that if I use Rs.move 4, and access the record, it is actually the
fifth record.


Of course. Recordsets start numbering at 0. Sorry about that.
 

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

Similar Threads

Problem with Recordset 2

Top