复杂访问公式逻辑

时间:2016-03-04 16:09:25

标签: excel ms-access if-statement ms-access-2010 formula

我在使用一些复杂的IF逻辑在MS Access查询中工作时遇到了一些麻烦,此时我感到很生气,所以我希望一双新眼睛可以帮助我解决我的问题。

我希望以下截图有助于使我的逻辑更清晰。

enter image description here

我对公式的最终结果是确定借款人(Borr)是否与提交的文件过期。在这种情况下,我只关心(P)FS 和/或 IE 文档。

过时的条件有点复杂,我将在下面解释。 TRUE 等同于过时, FALSE 符合要求。

  1. 如果NR框选中了(P)FSIE,那么 FALSE
  2. 如果NR未检查(P)FSIE并且(P)FS date is blank AND IE`日期为空,则 TRUE
  3. 这很容易,但现在是棘手的部分 CYYY =当前年份,PYYY =去年,PY2Y = 2年前

    1. 如果需要(P)FSIE且当前日期介于1/1 / CYYY和4/30 / CYYYY之间,且日期位于(P)FSIE在10/1 / PY2Y和4/30 / PYYY之间然后 FALSE Else TRUE
    2. 如果需要(P)FSIE且当前日期介于5/1 / CYYY和9/30 / CYYYY之间,且日期位于(P)FSIE不到1岁然后 FALSE Else TRUE
    3. 要记住的最后一件事是,只要有最新的(P)FSIE文档,结果就应该是 FALSE 。它们都不是必需的。它是或者。
    4. 此屏幕截图应有助于阐明日期公式:

      enter image description here

      这是我输入的最后一个Access公式,但仍然不起作用。我也觉得我知道为什么,但是我太炒了,试着继续解决这个问题:

          B1-FS-IE: IIf([annual_review].[prop_cd]<>"0056" And [nr_fs_b1]=True And 
      [nr_ie_b1]=True,False,IIf(([nr_fs_b1]=False And IsNull([fs_b1])) And ([nr_ie_b1]=False 
      And IsNull([ie_b1])),True,IIf(Month([fs_b1])>9 Or Month([fs_b1])<5 
      And (Month(Date())<5 And Date()-[fs_b1]>576) Or (Month([fs_b1])>4
       And Month([fs_b1])<10 And Date()-[fs_b1]>=365) Or Month([ie_b1])>9 
      Or Month([ie_b1])<5 And (Month(Date())<5 And Date()-[ie_b1]>576) 
      Or (Month([ie_b1])>4 And Month([ie_b1])<10 And Date()-[ie_b1]>=365),True,False)))
      

      最后,我放置了Excel标记,因为如果有人可以在Excel中解决这个问题,我可以转换为Access。

2 个答案:

答案 0 :(得分:0)

你还需要一个适当的方法来计算年份 - 比如这个函数:

Public Function Years( _
  ByVal datDate1 As Date, _
  ByVal datDate2 As Date, _
  Optional ByVal booLinear As Boolean) _
  As Integer

' Returns the difference in full years between datDate1 and datDate2.
'
' Calculates correctly for:
'   negative differences
'   leap years
'   dates of 29. February
'   date/time values with embedded time values
'   negative date/time values (prior to 1899-12-29)
'
' Optionally returns negative counts rounded down to provide a
' linear sequence of year counts.
' For a given datDate1, if datDate2 is decreased step wise one year from
' returning a positive count to returning a negative count, one or two
' occurrences of count zero will be returned.
' If booLinear is False, the sequence will be:
'   3, 2, 1, 0,  0, -1, -2
' If booLinear is True, the sequence will be:
'   3, 2, 1, 0, -1, -2, -3
'
' If booLinear is False, reversing datDate1 and datDate2 will return
' results of same absolute Value, only the sign will change.
' This behaviour mimics that of Fix().
' If booLinear is True, reversing datDate1 and datDate2 will return
' results where the negative count is offset by -1.
' This behaviour mimics that of Int().

' DateAdd() is used for check for month end of February as it correctly
' returns Feb. 28. when adding a count of years to dates of Feb. 29.
' when the resulting year is a common year.
'
' 2000-11-03. Cactus Data ApS, CPH.
' 2000-12-16. Leap year correction modified to be symmetrical.
'             Calculation of intDaysDiff simplified.
'             Renamed from YearsDiff() to Years().
' 2000-12-18. Introduced cbytMonthDaysMax.
' 2007-06-22. Version 2. Complete rewrite.
'             Check for month end of February performed with DateAdd()
'             after idea of Markus G. Fischer.

  Dim intDiff   As Integer
  Dim intSign   As Integer
  Dim intYears  As Integer

  ' Find difference in calendar years.
  intYears = DateDiff("yyyy", datDate1, datDate2)
  ' For positive resp. negative intervals, check if the second date
  ' falls before, on, or after the crossing date for a full 12 months period
  ' while at the same time correcting for February 29. of leap years.
  If DateDiff("d", datDate1, datDate2) > 0 Then
    intSign = Sgn(DateDiff("d", DateAdd("yyyy", intYears, datDate1), datDate2))
    intDiff = Abs(intSign < 0)
  Else
    intSign = Sgn(DateDiff("d", DateAdd("yyyy", -intYears, datDate2), datDate1))
    If intSign <> 0 Then
      ' Offset negative count of years to continuous sequence if requested.
      intDiff = Abs(booLinear)
    End If
    intDiff = intDiff - Abs(intSign < 0)
  End If

  ' Return count of years as count of full 12 months periods.
  Years = intYears - intDiff

End Function

答案 1 :(得分:0)

第一部分了解借款人是否已过时PFS,IE复选框,日期,

您可以在借款人控制的控制来源上使用以下等式来表示真或假

iif(checkPFS.value = True,CheckIE.value = True,False,iif(checkPFS.value = True,CheckIE.value = True,PFSDate ='',IEDate ='',True,False))