Ah, I see now. So basically if you have 79 records in the first table then you want page 4 to show the last 4 records of the first recordset then immediately start displaying (or partialy display) the next recordset.
Why not determine where you are by looking at your counter? First move your Dim statement outside your loop. VBScript is letting you get away with it right now, but technically it should be redeclaring those variables local to each loop. Move them Dim's outside to my mind at ease

Now When you start your next loop don't reset iCount. In the example above it would still be set at 4 after the first recordset is done. Go ahead and put in a couple line breaks, start a new table and add those lines to your iCount variable and then loop through the second recordset exactly like you have through the first. Since the iCount variable will now be starting at something like 8 or 9 (given our 79 records example) then it will finish the page, reset the variable to 0, and continue on.
Example (with other changes):
Code:
'iCount is a line count, tCount is number of records
Dim iCount, tCount
Do Until details.EOF
'increment total count
tCount = tCount + 1
If iCount mod 25 = 0 Then
'if this is not the first time through we need to end any previous paragraph and table tags
' on first time through count will = 0, on subsequent times it will be 25
If iCount = 25 Then
Response.Write "</table></p>"
'since we are on page > 1, we need a page break
Response.Write "<p style=""page-break-before: always"">" & topheader
Else
'we are on page 1, no page break necessary
Response.Write "<p>" & topheader
End If
'start the new table
Response.Write "<table width='100%' ><tr><th width='5%'>Line</th><th width='5%'>Qty</th></tr>"
iCount = 0 '// Reset it to 0 for the next 25
End If
'display the data row every time
Response.Write "<tr><td width='5%'>" & iCount2 & "</td><td align=right width='5%'>" & details("pcs") & "</td></tr>"
'increment line count + recordset
iCount = iCount + 1
details.MoveNext
Loop
'as long as we had data to loop through, tCount will be greater then 0 and there will be an open table and paragraph that needs to be closed.
If tCount > 0 Then Response.Write "</table></p>"
'pretty stuff
' we want a couple line breaks before starting the next table
' but there is no point unless we can add in the line breaks and the table header line without going past our 25 line count
If (iCount + 2 + 1) < 25 Then
Response.Write "<br>" & vbCrLf & "<br>" & vbCrLf
Response.Write "<p style=""page-break-before: always"">" & topheader
Response.Write "<table width='100%' ><tr><th width='5%'>Line</th><th width='5%'>Qty</th></tr>"
iCount = iCount + 3
Else
'if there wasn't room to continue on this page then pretend we are starting from scratch
iCount = 0
End If
'reset our tCount
tCount = 0
'start looping through second recordset
'----------------
' this section copied and pasted from above w/ recordset name changed
Do Until recordset2.EOF
'increment total count
tCount = tCount + 1
If iCount mod 25 = 0 Then
'if this is not the first time through we need to end any previous paragraph and table tags
' on first time through count will = 0, on subsequent times it will be 25
If iCount = 25 Then
Response.Write "</table></p>"
'since we are on page > 1, we need a page break
Response.Write "<p style=""page-break-before: always"">" & topheader
Else
'we are on page 1, no page break necessary
Response.Write "<p>" & topheader
End If
'start the new table
Response.Write "<table width='100%' ><tr><th width='5%'>Line</th><th width='5%'>Qty</th></tr>"
iCount = 0 '// Reset it to 0 for the next 25
End If
'display the data row every time
Response.Write "<tr><td width='5%'>" & iCount2 & "</td><td align=right width='5%'>" & recordset2("pcs") & "</td></tr>"
'increment line count + recordset
iCount = iCount + 1
recordset2.MoveNext
Loop
'as long as we had data to loop through, tCount will be greater then 0 and there will be an open table and paragraph that needs to be closed.
If tCount > 0 Then Response.Write "</table></p>"
Ok, several changes were made, i'll try to list them all:
1) You did not have end tags on your tr/th/td's so I added them
2) You were not ending your paragraph or table tags (except forthe last table after the loop) so I added in logic to close those tags and create less confusion for the browser
3) I moved the line that outputted the data row out of the if/then loop since this would be an identical step in every loop. No point in having it in two places, easier to edit this way.
4) I changed the if statement to check for mod 25 rather then = 25 so that there would actually be a paragraph and table tag created on the first page, i think the browser might have been guestimating that first table tag since you weren't outputting it. This makes the page less confusing to the browser and should be faster to render
5) added the if = 25 section inside the mod 25 section so we could tell whether we were starting the first page or a subsequent page and output the right paragraph tag (as well as close any outstanding tags)
There are several more minor modifications I could make, but this should solve your original dilemma as well as make the page load faster and load better across multiple browser types and versions.
-T