我想过滤一个表单,以显示明天和昨天的日期。
使用以下宏
,表单今天运行良好if [Forms]![issues]![OpenedDateFilter]="today"
applyfilter
where condition
(Year([Opened Date])=Year(Date()) And Month([Due Date])=Month(Date()) And
Day([Opened Date])=Day(Date()))
感谢您提供任何帮助或指示。
答案 0 :(得分:0)
你必须考虑到“明天”和“昨天”可能在另一年落下。因此,请使用 DateAdd :
Dim Offset As Integer
Select Case [Forms]![issues]![OpenedDateFilter]
Case "tomorrow"
Offset = 1
Case "yesterday"
Offset = -1
Case Else
Offset = 0
End Select
Me.Filter = "[Opened Date] = #" & Format(DateAdd("d", Offset, Date), "yyyy\/mm\/dd") & "#"
Me.FilterOn = True
如果[Due Date]
不是拼写错误,您可以使用 DateSerial :
Me.Filter = "[Opened Date] = #" & Format(DateSerial(Year(Date), Month([Due Date]), Day(Date) + Offset), "yyyy\/mm\/dd") & "#"