Not a full answer, as not sure of the structure of the table, but using a table with a primary key, I did the following, you'll need to do a count of the records and set the loop up according to that, but something along these lines
Sub test()
Dim strsql As String
Dim l As Long
Dim x As Long ' x will be recordcount/ l
l = 10000 ' max rows
For x = 1 To 3
strsql = "select top " & l & " y.* from (" & _
"Select top " & (x * l) & " * from [Table] order by [ID] desc" & _
") as Y order by y.id asc"
Debug.Print strsql
Next x
End Sub
This generates SQL like so
select top 10000 y.* from (Select top 10000 * from [Table] order by [ID] desc) as Y order by y.id asc
select top 10000 y.* from (Select top 20000 * from [Table] order by [ID] desc) as Y order by y.id asc
select top 10000 y.* from (Select top 30000 * from [Table] order by [ID] desc) as Y order by y.id asc
EDIT
Sub test()
Dim strsql As String
Dim l As Long
Dim x As Long ' x will be recordcount/ l
dim rst as adodb.recordset
l = 10000
For x = 1 To (dcount("id","table")/l)
strsql = "select top " & l & " y.* from (" & _
"Select top " & (x * l) & " * from [Table] order by [ID] desc" & _
") as Y order by y.id asc"
set rst=new adodb.recordset
rst.open strSQL, currentproject.connection, adOpenKeySet
worksheets(x).range("a1").copyfromrecordset rst
Next x
End Sub
Hope this helps
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…