我每周运行此代码,并尝试从 8/4 到当前检索数据。8 月份的前一周出现在报告中,但现在是 9 月份,8 月份的数据消失了。您能否帮助我指出更改代码以包含从 8/4 开始的每周数据的方向?
Function getDates(Optional forDate As String = "1/31/1999") As String Dim rst As Recordset
getDateRange = vbNullString
If forDate = "1/31/1999" Then
forDate = DateAdd("d", -1, Date)
End If
If DatePart("d", DateAdd("d", 1, forDate)) = 1 Then
eom = True
End If
Set rst = CurrentDb.OpenRecordset("SELECT Day, FiscalMonth, FiscalYear from tbl_Calendar where FiscalYear = (SELECT FIscalYear from tbl_Calendar where day = #" & _
Format(forDate, "Short Date") & "#) and FiscalMonth = (SELECT FiscalMonth from tbl_Calendar where day = #" & _
Format(forDate, "Short Date") & "#)")
If rst.EOF Then Exit Function
rst.MoveLast
rst.MoveFirst
getDates = CStr(rst.Fields("day").Value) & ";"
rst.MoveLast
If DateDiff("d", rst.Fields("day").Value, forDate) < 0 Then
eom = "False"
Else
eom = rst.Fields("FiscalMonth").Value & ", " & rst.Fields("FiscalYear").Value
End If
getDates = getDates & IIf(DateDiff("d", rst.Fields("day").Value, forDate) < 0, CStr(forDate), CStr(rst.Fields("day").Value)) & ";" & eom
rst.Close
Set rst = Nothing
End Function