Ms access 使用相同的搜索条件。我也尝试过这样做,我在组合框中列出了供应商,并尝试使用vba代码来过滤记录私有子cboVendors_AfterUpdate()Me.filter=“[vendors]=”&char(34)&Me.cboVendors&char(34)

Ms access 使用相同的搜索条件。我也尝试过这样做,我在组合框中列出了供应商,并尝试使用vba代码来过滤记录私有子cboVendors_AfterUpdate()Me.filter=“[vendors]=”&char(34)&Me.cboVendors&char(34),ms-access,vba,Ms Access,Vba,使用相同的搜索条件。我也尝试过这样做,我在组合框中列出了供应商,并尝试使用vba代码来过滤记录私有子cboVendors_AfterUpdate()Me.filter=“[vendors]=”&char(34)&Me.cboVendors&char(34)Me.FilterOn=True End Sub我正在使用Access 2016,如果我dim chae(34)我在查询表达式[vendors]中出现语法错误(missingOperator)=Ace硬件供应商选择了我在Youtube视频在线上

使用相同的搜索条件。我也尝试过这样做,我在组合框中列出了供应商,并尝试使用vba代码来过滤记录私有子cboVendors_AfterUpdate()Me.filter=“[vendors]=”&char(34)&Me.cboVendors&char(34)Me.FilterOn=True End Sub我正在使用Access 2016,如果我dim chae(34)我在查询表达式[vendors]中出现语法错误(missingOperator)=Ace硬件供应商选择了我在Youtube视频在线上找到的代码,该视频似乎与Access 2007兼容
Function FindRecordCount(strSQL As String) As Long
     Dim db As Database
     Dim rstRecords As Recordset

'On error GoTo ErrorHandler
            Set db = CurrentDb
            Set rstRecords = db.OpenRecordset("TblPurchases")
    If rstRecords.EOF Then
    FindRecordCount = 0
Else
    rstRecords.MoveLast
    FindRecordCount = rstRecords.RecordCount

End If
   rstRecords.Close
   db.Close
Set rstRecords = Nothing
Set db = Nothing
End Function
   Sub Search()
   Dim strCriteria, task As String

      Me.Refresh
     If IsNull(Me.TxtPurchaseDateFrom) Or IsNull(Me.TxtPurchaseDateTo) 
 Then
   MsgBox "Please enter the date range", vbInformation, "Date Range 
   Required"
    Me.TxtPurchaseDateFrom.SetFocus
  Else
    strCriteria = "([Date of Purchase] >= #" & Me.TxtPurchaseDateFrom & 
   "# and [Date of Purchase] <= #" & Me.TxtPurchaseDateTo & "#)"
    task = "select * from TblPurchases where( " & strCriteria & ") order 
    by [Date of Purchase] "
   DoCmd.ApplyFilter task
    Me.TxtTotal = FindRecordCount(task)
End If
Set rstRecords = db.OpenRecordset("TblPurchases")
Function FindRecordCount(dateFrom As Date, dateTo As Date) As Long
    Dim db As DAO.Database
    Dim QDF As DAO.QueryDef
    Dim rstRecords As DAO.Recordset
    Dim SQL As String

    SQL = "SELECT COUNT(*) FROM TblPurchase WHERE([Date of Purchase] >= #@dateFrom# AND [Date of Purchase] <= #@dateTo#)"

    Set db = CurrentDb
    Set QDF = db.QuerDefs(SQL)
    QDF.Paramaters("@dateFrom").Value = dateFrom
    QDF.Paramaters("@dateTo").Value = dateTo

    Set rstRecords = QDF.OpenRecordset("TblPurchases")

    If rstRecords.EOF Then
        FindRecordCount = 0
    Else
        rstRecords.MoveLast
        FindRecordCount = rstRecords.RecordCount
    End If

    rstRecords.Close
    QDF.Close
    db.Close
    Set rstRecords = Nothing
    Set QDF = Nothing
    Set db = Nothing
End Function
=DCount("*","TblPurchase ","[Date of Purchase] Between #" & Format(Nz(Me!TxtPurchaseDateFrom.Value,Date()), "yyyy\/mm\/dd") & "# And #" & Format(Nz(Me!TxtPurchaseDateTo.Value,Date()), "yyyy\/mm\/dd") & "#")