【问题标题】:FindFirst Syntax Error with date criteria日期条件的 FindFirst 语法错误
【发布时间】:2020-04-25 22:23:43
【问题描述】:

我在 VBA Access 中有以下几行,但我收到 FindFirst 的语法错误,我不明白为什么。

criteria = "[HolidayDate] = " & "#" & myDate & "#"
rst.FindFirst (criteria)
If rst.NoMatch Then
    count = count + 1
End If

【问题讨论】:

  • 是的,HolidayDate 是 "Holiday"-Table 中的日期类型字段
  • mydate = CDate("01.0" & Int(Me.cboMonth) & "." & Int(Me.cboYear))
  • 目的是统计一个月的工作日数
  • 我找到了另一个解决方案
  • 问题可能是括号。删除它们:rst.FindFirst 条件

标签: vba ms-access syntax-error findfirst


【解决方案1】:

循环遍历记录集不是解决方案。

如果 HolidayDate 确实是 DateTime 数据类型,这将起作用:

criteria = "[HolidayDate] = #" & Format(myDate, "yyyy\/mm\/dd") & "#"
rst.FindFirst criteria

如果不是,则有其他事情发生。

【讨论】:

    【解决方案2】:
    Do While mydate <= EndOfMonth
            If Weekday(mydate, vbMonday) < 6 Then
                 With rst
                    .MoveFirst
                    flag = False
                    Do While Not .EOF
                        If CDate(.Fields("HolidayDate").Value) = myDate Then
                            flag = True
                        End If
                    .MoveNext
                    Loop
                    If flag = False Then
                        count = count + 1
                    End If
                End With
            End If
            myDate = myDate + 1
        Loop
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-04
      • 1970-01-01
      • 1970-01-01
      • 2016-04-21
      • 1970-01-01
      • 2017-12-15
      相关资源
      最近更新 更多