显示所有记录的消息框条件过滤器

Message box criteria filter showing all records

我的主菜单窗体中有一个按钮,它必须显示所有仪器都需要校准的提醒。 标准是:“显示小于今天的记录以及从今天起 +7 天的记录” 但是我无法对后者进行编码,因此它显示了所有未来的记录。 下面是我的代码,请帮忙。

Private Sub cmddept_Click()
    Dim RS As DAO.Recordset
    Dim strMsg As String
    
    Set RS = CurrentDb.OpenRecordset("select * from (" & Me.RecordSource & ")", dbOpenSnapshot, dbReadOnly)
    
    With RS
        If Not (.BOF And .EOF) Then
            .MoveFirst
            While Not .EOF
                If ![Next_Calibration] > Date - 7 Then
                  strMsg = strMsg & ![EQUIPMENT_number] & vbTab & vbTab & ![Calibrating_agency] & vbTab & vbTab & ![Next_Calibration] & vbCrLf
                End If
                .MoveNext
            Wend
        End If
        .Close
    End With
    Set RS = Nothing
    If strMsg <> "" Then
       strMsg = "You have to Calibrate the following!!!:" & vbCrLf & vbCrLf & _
"------------------------------------------------------------------------------------------------------------------------" & vbCrLf & _
"Equipment Name" & vbTab & vTab & "Agency Name" & vTab & vbTab & "Due Date" & vbCrLf & _
"-------------------------------------------------------------------------------------------------------------------------" & vbCrLf & _
strMsg
Else
strMsg = "No record to is due for calibration"
End If
    
    MsgBox strMsg, vbInformation + vbOKOnly
End Sub

我会这样做:

    Set RS = CurrentDb.OpenRecordset("select * from " & Me.RecordSource & " WHERE [Next_Calibration] <= DateAdd('d', 7, Date())", dbOpenSnapshot, dbReadOnly)
    
    With RS
        If Not (.BOF And .EOF) Then
            .MoveFirst
            While Not .EOF
                  strMsg = strMsg & ![EQUIPMENT_number] & vbTab & vbTab & ![Calibrating_agency] & vbTab & vbTab & ![Next_Calibration] & vbCrLf
                .MoveNext
            Wend
        End If
        .Close
    End With
    Set RS = Nothing
' continue with your code