I'm trying to create a module that returns a SinceDate when having more than one UntilDate per ID, for example:
REL_ID, UNTIL, fSince
1, 10/10/08, 0
2, 09/10/08, 0
2, 30/10/08, 10/10/08
3, 10/10/08, 0
So far it works okay, the problem is that fSince returns the value that corresponds to the last entry for all of em, in this case, last value is:
3, 10/10/08, 0
So it returns:
REL_ID, UNTIL, fSince
1, 10/10/08, 0
2, 09/10/08, 0
2, 30/10/08, 0
3, 10/10/08, 0
If last value would have been "2, 30/10/08, 10/10/08", would have returned 10/10/08 for all the records. What's wrong with this module? Shall I use some criteria thing in the SQL of it?
REL_ID, UNTIL, fSince
1, 10/10/08, 0
2, 09/10/08, 0
2, 30/10/08, 10/10/08
3, 10/10/08, 0
So far it works okay, the problem is that fSince returns the value that corresponds to the last entry for all of em, in this case, last value is:
3, 10/10/08, 0
So it returns:
REL_ID, UNTIL, fSince
1, 10/10/08, 0
2, 09/10/08, 0
2, 30/10/08, 0
3, 10/10/08, 0
If last value would have been "2, 30/10/08, 10/10/08", would have returned 10/10/08 for all the records. What's wrong with this module? Shall I use some criteria thing in the SQL of it?
Code:
Option Compare Database
Option Explicit
Public Function fSince()
Dim strSQL As String
Dim strText As String
Dim datePrev As Long
Dim flag As Integer
Dim IDEM2 As Integer
flag = 0
strSQL = "SELECT REL_ID, HASTA FROM tblAcuerdos GROUP BY REL_ID, HASTA ORDER BY REL_ID, HASTA"
'Open a Recordset and loop through it to fill the text box txtTest with
'the faults Repaired >>>reprorted by the customer<<<<
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL, dbOpenForwardOnly)
flag = 0
Do Until rs.EOF
If (flag > 0) Then
If (IDEM2 = rs!REL_ID) Then
fSince = datePrev + 1
Else
fSince = 0
End If
End If
datePrev = rs!HASTA
IDEM2 = rs!REL_ID
flag = flag + 1
rs.MoveNext
Loop
rs.close
Set rs = Nothing
Set db = Nothing
End Function