Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 如何根据MS Access VBA代码中的昨天日期筛选表?_Excel_Vba_Ms Access - Fatal编程技术网

Excel 如何根据MS Access VBA代码中的昨天日期筛选表?

Excel 如何根据MS Access VBA代码中的昨天日期筛选表?,excel,vba,ms-access,Excel,Vba,Ms Access,我一直在尝试使用TransferSpreadsheet进行excel导出的简单访问 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" 'P

我一直在尝试使用
TransferSpreadsheet
进行excel导出的简单访问

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创建查询:

从AttendanceLogs中选择*,其中AttendanceDate=DateAdd(“d”,-1,Date())
把它留作,比如说,昨天的出席

然后调整代码:

Dim query\u to\u导出为字符串
'要导出的访问查询的名称:
查询至导出=“AttendanceLogsDay”
DoCmd.transfer电子表格acExport,acSpreadsheetTypeExcel12Xml,查询到导出,excel文件名

看看这篇文章@哈伦24小时,我一定会试试的。谢谢你的建议。试试这个。。如果您的表包含列“Date”,则可以将其筛选为<代码>表\u to \u export.Filter=“日期=日期-1”。。。。table_to_export.FilterOn=TrueNaresh bOple,感谢您的评论,我也尝试了一下。给出一个错误-无效的限定符也没有涉及表单,只是为了让您知道@NareshBhopleGustav,谢谢您的详细回答。。帮助很大。