214-564-5316
Thursday, September 09, 2010

Pagination in Access Databases
Link to download code


This combination DB and CSS script is modeled off of the popular DIGG web site pagination style.
The key component is this line:
ps = getPaginationString(page, mycount, 5, 2, "pagination.asp?foo=bar")
Where the numeral "5" is the number of returned responses per "page".
In addition, when changing that variable you will need to make a slight alteration to the database sql statement:
sql = "SELECT * FROM Clients WHERE ID > "&((Cint(page)*5)-5)&" AND ID <= "&Cint(page)*5&";"
By changing all instances of the numeral "5" to the number of returned rows per page you want to use.
Our database table for this example is named "Clients" you would, of course, need to change your DB table and connections in the code.
Download the code here.

One database call creates a record count:
DBConn.Open ConnectStr
sql = "SELECT COUNT(*) AS mycount FROM Clients "
Set RsCOUNT = Server.CreateObject("ADODB.Recordset")
RsCOUNT.Open sql, DBConn, 3, 3
mycount=RsCOUNT("mycount")

While the other grabs the records:
DBConn1.Open ConnectStr
sql = "SELECT * FROM Clients WHERE ID > "&((Cint(page)*5)-5)&" AND ID <= "&Cint(page)*5&";"
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open sql, DBConn1, 3, 3
Do While Not Rs.EOF

Client Name
Join Date
Tool Time
6/30/2010
Mollye May
7/1/2010
Sally Amith
7/15/2010
John Doe
7/30/2010
Sammy Spade
8/1/2010