Calculating position of Record within Recordset

Results 1 to 3 of 3

Thread: Calculating position of Record within Recordset

  1. #1
    Join Date
    Dec 1969
    Posts
    69

    Default Calculating position of Record within Recordset

    Once I open Recordset (sorted the way I want), is there any efficient and fast way I can calculate/determine the position of the particular record (let&#039s say with some ID) within that Recordset?<BR><BR>I know I can count records one by one (rs.MoveNext), but I wonder is there any better way?

  2. #2
    Join Date
    Dec 1969
    Posts
    1,315

    Default RE: Calculating position of Record within Recordset

    Hi Goran,<BR><BR>Here&#039s one way:<BR>Suppose one field is an ID (autonumber or number, but ascending).<BR>The ID&#039s don&#039t have to be in sequence (when we delete records,<BR>the ID&#039s are no longer in sequence but of course still ascending).<BR><BR>Suppose you want to know the position of a record, given its ID is 50. Then, use SQL:<BR>itsID = 50<BR><BR>SQL = "SELECT Count(*) As Position FROM Tabel1 WHERE ID &#060;= " & itsID<BR><BR>Set rs = cn.Execute(SQL)<BR>To get the position, use: <BR>Response.Write("Its position is: " & rs("Position"))<BR><BR>To get the position of a record with ID = 80, reassign<BR>itsID = 80 etc.<BR><BR>Let me know if you need any help on this.<BR><BR>Note: <BR>There are always ways to access information on a database without having to know the positions of records.<BR><BR>Cheers<BR><BR>John Weeflaar<BR><BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    69

    Default Of course, how stupid I was...

    Hi John,<BR><BR>No I don&#039t use ID to sort records but date and some other field, but the same logic apply - no problem.<BR><BR>Well, I had to overcome little problem with date format conversion - no big deal.<BR><BR>It works!<BR>Of course, how stupid I was...<BR><BR>... But then, there are always these good people here to help you out, right?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •