为什么以下代码会提示溢出Private Sub Command9_Click() Dim db As DAO.Database Dim rs As DAO.Recordset Dim strSQL As String Dim strFileName As String Dim i As Integer '设置导出文件路径和文件名 strFileName = "C:\Users\icd\Desktop\流水分割" Set db = CurrentDb() strSQL = "SELECT 导出数据.* FROM 导出数据" Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot) '每10000条记录导出到一个新的文件 Do While Not rs.EOF If i Mod 10000 = 0 Then If i <> 0 Then DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "ExportData", strFileName & Format(i, "000000") & ".xlsx", True End If rs.Close Set rs = db.OpenRecordset("导出数据", dbOpenSnapshot) End If i = i + 1 rs.MoveNext Loop '导出最后一份文件 If i Mod 10000 <> 0 Then DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "导出数据", strFileName & Format(i - (i Mod 10000), "000000") & ".xlsx", True End If rs.Close Set rs = Nothing Set db
时间: 2024-02-14 09:12:01 浏览: 171
这段代码提示溢出的原因可能是由于变量 i 的数据类型为 Integer,而 i 的值超出了 Integer 数据类型的范围(-32768 到 32767),导致溢出。建议将 i 的数据类型改为 Long,这样可以表示更大的数值,避免溢出。修改后的代码如下:
```
Private Sub Command9_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strFileName As String
Dim i As Long '修改为 Long 类型
'设置导出文件路径和文件名
strFileName = "C:\Users\icd\Desktop\流水分割"
Set db = CurrentDb()
strSQL = "SELECT 导出数据.* FROM 导出数据"
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
'每10000条记录导出到一个新的文件
Do While Not rs.EOF
If i Mod 10000 = 0 Then
If i <> 0 Then
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "ExportData", strFileName & Format(i, "000000") & ".xlsx", True
End If
rs.Close
Set rs = db.OpenRecordset("导出数据", dbOpenSnapshot)
End If
i = i + 1
rs.MoveNext
Loop
'导出最后一份文件
If i Mod 10000 <> 0 Then
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "导出数据", strFileName & Format(i - (i Mod 10000), "000000") & ".xlsx", True
End If
rs.Close
Set rs = Nothing
Set db
End Sub
```
阅读全文