Loop

J

John Smith

I'm trying to perform a loop to display the contents of my DB, the only
issue is that I would only like to display 10 results maximum this is
relatively easy but what happens if there are less than 10 results in the
DB. If I was going to do a :

Do Until objRS.EOF

Then it would display the full records, likewise if i put a counter on the
loop then it will run into errors if I have less records than the
count.......

ideas ?

thanks.
 
B

Bob Barrows

John said:
I'm trying to perform a loop to display the contents of my DB, the
only issue is that I would only like to display 10 results maximum
this is relatively easy but what happens if there are less than 10
results in the DB. If I was going to do a :

Do Until objRS.EOF

Then it would display the full records, likewise if i put a counter
on the loop then it will run into errors if I have less records than
the count.......

ideas ?

thanks.

What database?
With Access and SQL Server, you can use the TOP n construct in your query to
limit the records returned (SELECT TOP 10 <field list> FROM table ...). With
SQL Server, you can also use SET ROWCOUNT to do the same thing.

If you have an antique database that does not support TOP, then simply
combine your counter idea with your DO loop:

dim i
i = 0
Do Until rs.eof OR i = 10
....
i = i + 1
rs.movenext
loop

HTH,
Bob Barrows
 
J

Jeff Cochran

I'm trying to perform a loop to display the contents of my DB, the only
issue is that I would only like to display 10 results maximum this is
relatively easy but what happens if there are less than 10 results in the
DB. If I was going to do a :

Do Until objRS.EOF

Then it would display the full records, likewise if i put a counter on the
loop then it will run into errors if I have less records than the
count.......

ideas ?

Why not just do:

Do Until objRS.EOF OR count=10

Jeff
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top