Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading middle records into a record set

Status
Not open for further replies.

cabobound

Programmer
Jul 11, 2007
80
US
Is there a way to load only certain records into a recordset? For example: I have a table with 1000 records but only want records 250-500.

My connection is:
Set aConn = Server.CreateObject("ADODB.Connection")
DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtemp=dsntemp & "DBQ=" & server.mappath("/myDB.mdb")
aConn.Open DSNtemp
 
That looks like "paging", which can be solved in many different ways. eg:

Code:
dim oRS
set oRS = server.CreateObject("ADODB.recordset")
oRS.Open "select * from myTable,aConn,3,1,1

oRS.PageSize =250
oRS.AbsolutePage = 2
 
nCount = 1

Response.Write "<table align=center>"
while not oRS.eof and nCount <= 250
     response.write "<tr><td>" & oRS.fields(0) & _
     "</td><td>" & oRS.fields(1)
     ' etc
 oRS.movenext
 nCount = nCount + 1
wend
response.write "</table>"
oRS.close

This is really a hard-coded "page 2" (record 250-500 from 1000). But of course you can make it more generic with parameters for oRS.PageSize and oRS.AbsolutePage.

It is also possible to create an "empty" record set and insert specific records into it (like adding records to a table), but i don't think that are looking for such an solution here...


 
I have a complicated script that produces a report with totals along with whether or not there are less than 2000 records (that seems to be where the browser buffer limit is for this report). So if there are under 2k, just do report, otherwise get option of which set of 2000 to grab. IE: 7500 records and they need 2001-4000. So I dont want to load the entire recordset, just a partial.

Is there a way to have 2 parameters for a DO WHILE loop?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top