访问查询。如果记录截止日期 = 上周在单元格中插入是

Access Query. If records Due Date = Last Week Insert Yes in Cell

大家早上好,

我正在研究以下内容,但我一辈子都弄不明白。我有 table,其中包含一堆截止日期。我想要做的是添加一个查询,该查询添加另一个字段并在日期等于上周的一天时插入一个是。老实说,我需要它插入是,只要它不 = 这周。

我试过使用:

Urgent: IIf([Due Date]=[Due Date] 
Between 
DateAdd("d",1-Weekday(Date()) 7, Date()) And 
DateAdd("d",1-Weekday(Date())-1, Date()),"Yes","")

运气不好。我在这里错过了什么?!

谢谢大家。干杯。

如果 'not this week' 表示上周六及之前,return 紧急。不知道如果没有代码你会怎么做。

根据当前日期获取本周第一天的辅助函数。将其粘贴到新的或现有的全局模块中。

Function FirstDateOfTheWeek() As Date
  Dim dt As Date

  If Weekday(Date) = vbSaturday Then
    FirstDateOfTheWeek = DateAdd("y", -6, Date) 'today is Saturday? then return previous Sunday
  ElseIf Weekday(Date) = vbSunday Then
    FirstDateOfTheWeek = Date 'today is Sunday? then return Sunday because its the first day of the week
  Else 'weekday, so just go backwards until we hit previous sunday's date
    dt = Date
    While Weekday(dt) <> vbSunday
      dt = DateAdd("y", -1, dt)
    Wend
    FirstDateOfTheWeek = dt
  End If

End Function

要从查询中调用的 IsUrgent 函数。将其粘贴到新的或现有的全局模块中。

Function IsUrgent(dt As Variant) As String

  If IsNull(dt) Then 'if null date is passed then return blank string; Variant chosen instead of date for this case; change it to N/A if you want?
    IsUrgent = ""
    Exit Function
  End If

  If dt < FirstDateOfTheWeek Then
    IsUrgent = "Yes"
  Else
    IsUrgent = ""
  End If

End Function

调用 IsUrgent() 函数的查询列:

IsUrgent: IsUrgent([Due Date])