A single Query with a Calculated Field can solve the problem. Pass to a Public Function the Received and Completed Dates which will then be evaluted and a Priority Value returned based upon the Input.
- SQL Statement:
Code:SELECT DISTINCT Table1.[Project Received], Table1.[Construction Complete], fCalcDaysOutstanding([Project Received],[Construction Complete]) AS Priority FROM Table1 ORDER BY fCalcDaysOutstanding([Project Received],[Construction Complete]);
- Table Values:
Code:PK Field1 Project Received Construction Complete 1 100.664 5/9/2013 7/1/2013 4 98.891 5/4/2013 6/14/2013 5 102.344 5/12/2013 7/27/2013 6 101.527 5/1/2013 7 103.135 5/21/2013 5/29/2013 21 5/17/2013 22 12/12/2012 4/30/2013
- Results:
Code:Project Received Construction Complete Priority 5/21/2013 5/29/2013 1 5/4/2013 6/14/2013 2 5/9/2013 7/1/2013 2 5/12/2013 7/27/2013 3 12/12/2012 4/30/2013 4 5/17/2013 99 5/1/2013 99
- Function Definition:
Code:Public Function fCalcDaysOutstanding(varReceived As Variant, varCompleted As Variant) Dim intDaysDiff As Integer 'If either the Received or Completed Date is NULL then return a pre-determined Value If IsNull(varReceived) Or IsNull(varCompleted) Then fCalcDaysOutstanding = 99 Exit Function End If intDaysDiff = DateDiff("d", varReceived, varCompleted) Select Case intDaysDiff Case Is < 30 fCalcDaysOutstanding = 1 Case Is < 60 fCalcDaysOutstanding = 2 Case Is < 90 fCalcDaysOutstanding = 3 Case Else fCalcDaysOutstanding = 4 End Select End Function
Comment