Obviously, you can't count on a specific number. You will have to store
the
last number in the query for use in the Where clause of the next one.
This
means that you will have to programmaticly create the "Next 10" query each
time. Are you using ASP for this?
For instance. From my NumberedQuery sample, we have this, which numbers
the
records in the query:
SELECT (Select Count(1) FROM Authors A WHERE A.AuID <=Authors.AuID)
AS Sequence, Authors.AuID, Authors.AuPhone, Authors.AuName
FROM Authors
ORDER BY Authors.AuID;
To show the Top 5 from this, it would be:
SELECT TOP 5 (Select Count(1) FROM Authors A WHERE
A.AuID <=Authors.AuID) AS Sequence, Authors.AuID,
Authors.AuPhone, Authors.AuName
FROM Authors
ORDER BY Authors.AuID;
To see records 6-10, you'd have to store the value of the last record (in
this case it IS 5, but it wouldn't have to be) and use that in the Where
clause:
SELECT TOP 5 (Select Count(1) FROM Authors A WHERE
A.AuID <=Authors.AuID) AS Sequence, Authors.AuID,
Authors.AuPhone, Authors.AuName
FROM Authors
WHERE ((((Select Count(1) FROM Authors A
WHERE A.AuID <=Authors.AuID))>5))
ORDER BY Authors.AuID;
Programmatically, it would need to be something like this:
'******* begin air code *********************
Dim LastRecord as Long
Dim strSQL as String
Dim qdf as DAO.QueryDef
LastRecord = 5 '(you would need to store this programmically)
strSQL = "SELECT TOP 5 (Select Count(1) FROM Authors A " & _
"WHERE A.AuID <=Authors.AuID) AS Sequence, Authors.AuID, " & _
"Authors.AuPhone, Authors.AuName " & _
"FROM Authors " & _
"WHERE ((((Select Count(1) FROM Authors A " & _
"WHERE A.AuID <=Authors.AuID))> " & LastRecord & ")) " & _
"ORDER BY Authors.AuID;"
set qdf = CurrentDb.CreateQuery("Next10", strSQL)
'******* end air code *********************
Naturally, if you are using ASP or ADO, the code would have to change
slightly, but the idea is still the same. You would recreate the "Next10"
query each time you change a page, storing the last value from the
currrent
page, and using that as a variable in creating the query. You can
similarly
create a "Previous10" query by storing the first value from the current
page.
I have more examples of creating queries programmatically on my website.
Most of them start with "CreateQueries".
--
--Roger Carlson
www.rogersaccesslibrary.com
Reply to: Roger dot Carlson at Spectrum-Health dot Org
Saber said:
I'm using an 'id' field as AutoNumber.
I can use the 'id' to show next 10 records, but what if
I delete a record in middle of table?
BTW- good examples in your website, thank you.
Roger Carlson said:
There is no such syntax for SQL. You'll have to use a WHERE clause
that
excludes your first 10 records. How do you do that? Access doesn't have
"record numbers" as such, but you can create a query which numbers
them.
On
my website (see sig below) is a small sample database called
"NumberedQuery.mdb" which shows two ways to do it. It adds a column
called
Sequence that numbers the query. You can add a TOP 10 predicate and also
a
WHERE clause Where Sequence > 10.
--
--Roger Carlson
www.rogersaccesslibrary.com
Reply to: Roger dot Carlson at Spectrum-Health dot Org
"Saber" <saber[--AT--]maghalat.com> wrote in message
I'm using "Select TOP 10 * From tblPost" to show my first 10 posts in
a
weblog.
to create "next 10 posts" button, how can I change my command text?
I need something like: Select Records[11-20] From tblPosts