【发布时间】:2020-07-13 23:04:51
【问题描述】:
运行时错误“3190” 定义的字段过多
当我单击在DoCmd.TransferSpreadsheet 中调用查询的按钮时收到此错误:
'------------------------------------------------------------
' Creates the excel file in the path passed to it
' Returns the path of the file including the file name and extension
'------------------------------------------------------------
Function CreateExcelFile(Path As String) As String
Dim outputFileName As String
outputFileName = Path & "SummaryTemplate.xlsx"
Dim Queries(1 To 4) As String
Queries(1) = "qryProcessAuditScores" 'Audit scores
Queries(2) = "qryProcessAuditStations" 'Audit Stations
Queries(3) = "qryProcessNCs" 'Number of NC's
Queries(4) = "qryProcessAuditCount" 'number of audits from the year
Dim qry
For Each qry In Queries
DoCmd.TransferSpreadsheet _
acExport, _
acSpreadsheetTypeExcel12, _
qry, _
outputFileName, _
True
Next
CreateExcelFile = outputFileName 'return the full path
End Function
当我在 Access 中手动运行查询时,我没有收到此类错误。我尝试过压缩和修复数据库,但没有成功。还有其他想法吗?
谢谢
【问题讨论】:
-
试试
for qry = 1 to 4和Queries(qry)? -
或者,在 docmd.transferspreadsheet 行放置一个断点,并检查
qry的值 -
我尝试这样做只是为了确保但这是一个循环问题。这更清楚地是一个调用或查询问题,代码是作为我的方法的参考,而不是因为我不确定。字符串存在并被传递。唯一我不完全确定的是 DoCmd.TransferSpreadsheet 但我已经看过很多次了。感谢您的想法,但事实并非如此。
-
我感觉这是 Excel 工作簿的问题,而不是查询的问题,尽管我不知道标量数组如何支持 For...Each。可能是文件已经存在,因为每个查询都被输出到同一个文件?它可能不知道如何处理覆盖并引发错误。即使不是,每个查询写入的范围是多少?如果没有定义的范围,我认为它始终是工作表集合中的第一个。我认为您需要认真考虑文件处理以及数据将在这些工作簿中的最终位置
-
真正烦人的部分是在错误出现之前它工作了一两天。它解决了那里的现有文件,它将每个查询结果附加到以查询命名的工作簿上的新工作表中。每一页都只是从 A1 开始,取出它需要的所有单元格(总是小于 10 x 10),而且效果很好。此外,您不能定义导出范围,只能定义导入。
标签: ms-access vba ms-access-2010