我一直在尝试使用进行对Excel导出的简单访问TransferSpreadsheet
。
Public Function Test()
Dim table_to_export As String
Dim excel_file_name As String
Dim has_header As Boolean
'Name of the Access table to export:
table_to_export = "AttendanceLogs"
'Path of the file to put data in. Update with your own path:
excel_file_name = "F:\Test\Att.xlsx"
'Export headers with data:
has_header = True
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, table_to_export, excel_file_name
End Function
导出工作正常,表有一个列AttendanceDate
。
有什么办法可以根据日期列将过滤器添加到表中(仅过滤昨天的记录),然后导出到excel
创建一个查询:
Select * From AttendanceLogs Where AttendanceDate = DateAdd("d", -1, Date())
将其另存为,例如AttendanceLogsYesterday。
然后调整您的代码:
Dim query_to_export As String
' Name of the Access query to export:
query_to_export = "AttendanceLogsYesterday"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, query_to_export, excel_file_name
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句