下面是我的程序里的一个函数,你参考一下。
Function BackupData(myOpen, ff) As Boolean
On Error Resume Next
Dim arr(), i, myOpen1, ID As Currency
BackupData = False
rs1.PageSize = 65535
myOpen1 = "select * from (" & myOpen & ") order by ID"
rs1.Open myOpen1, con1, 1, 3
ps = rs1.PageCount
ReDim arr(ps)
For i = 1 To ps
rs1.AbsolutePage = i
arr(i) = rs1.Fields("ID")
Next
rs1.Close
If Err <> 0 Then GoTo myend
If arr(1) = 0 Then GoTo myend
For i = 1 To ps
myOpen1 = "select * into [Excel 8.0;database=" & ff & "].Sheet" & i & " from (" & myOpen & ") where ID >= " & arr(i)
If i < ps Then myOpen1 = myOpen1 & " and ID<" & arr(i + 1)
rs1.Open myOpen1 & " order by ID"
Next
BackupData = Err = 0
Exit Function
myend:
p = InStrRev(ff, "\")
rs1.Open "select * into [Text;HDR=YES;DATABASE=" & Left(ff, p) & "]." & Mid(ff, p + 1) & ".txt from (" & myOpen & ")"
ff = Left(ff, p) & "schema.ini"
If Dir(ff) <> "" Then Kill (ff)
BackupData = Err = 0
End Function