Access 2000 - I am implementing a Tracking System that among other things requires that a tickler be provided so that the users will know what is to be done next on each individual case. I developed a Union Query that is doing the job except for this section. See the code below. In the first section "NO ACTION" I expected to get rows for those items that did not have any Calendar event. I am getting nothing eventhough there are 4.
In the second section "NO ACTION2" I expected to get rows for those items that only have closed Calendar events (Status <> "PENDING"). I am getting those plus other that have open (Status = "PENDING") calendar events. I have worked on this problems for several days and cannot find what is wrong. Any help will be deeply appreciated.
In the second section "NO ACTION2" I expected to get rows for those items that only have closed Calendar events (Status <> "PENDING"). I am getting those plus other that have open (Status = "PENDING") calendar events. I have worked on this problems for several days and cannot find what is wrong. Any help will be deeply appreciated.
Code:
QUERY:
SELECT "NO ACTION" AS Cat, "NO ACTION" AS Item, "NO ACTION" AS Action, Date() AS ActDate, tblTracking.Tatno AS TatNo, tblTracking.DisplTatno AS DispTat, tblTracking.ALJName AS Judge, LEFT(tblTracking.Taxpayer,20) AS TP, tblTracking.Related AS Rel, tblTracking.Consol AS Con, "A" AS Class
FROM tblTracking
WHERE IsNull(tblTracking.ClosedDate)
AND tblTracking.Consol <> "C"
AND tblTracking.SineDie = "N"
AND not isNull([tblTracking].[AcknowledgeDate])
AND ( (Exists (Select * FROM tblCalendar INNER JOIN tblTracking on tblTracking.Tatno = tblCalendar.Tatno
WHERE tblTracking.Tatno = tblCalendar.Tatno)) = false)
UNION SELECT "NO ACTION2" AS Cat, "NO ACTION2" AS Item, "NO ACTION2" AS [Action], Date() AS ActDate, tblTracking.Tatno AS TatNo, tblTracking.DisplTatno AS DispTat, tblTracking.ALJName AS Judge, Left(tblTracking.Taxpayer,20) AS TP, tblTracking.Related AS Rel, tblTracking.Consol AS Con, "A" AS Class
FROM tblTracking
WHERE tblTracking.Consol<>"C"
AND IsNull(tblTracking.ClosedDate)
AND tblTracking.SineDie="N"
AND NOT IsNull(tblTracking.AcknowledgeDate)
AND ((Exists (Select * FROM tblCalendar INNER JOIN tblTracking on tblTracking.Tatno = tblCalendar.Tatno
WHERE tblTracking.Tatno = tblCalendar.Tatno)) AND Needcalendar(tblTracking.Tatno) = 2)
ORDER BY Tatno, actdate;
VBA CODE
'================================================
Public Static Function NeedCalendar(strTatno As String) As Integer
Dim strSqlx As String
Dim dbx As Database
Dim recx As Recordset
Dim reopen As Integer
Dim reclosed As Integer
reopen = 0
reclosed = 0
strSqlx = "tblCalendar"
Set dbx = CurrentDb()
Set recx = dbx.OpenRecordset(strSqlx)
If Not recx.BOF And Not recx.EOF Then
Do While Not recx.EOF
If recx("Tatno") = strTatno Then
If recx("Status") = "PENDING" Then
reopen = reopen + 1
Else
reclosed = reclosed + 1
End If
End If
recx.MoveNext
Loop
End If
NeedCalendar = SetExit(reopen, reclosed)
recx.Close
Set recx = Nothing
End Function
'================================================
Public Static Function SetExit(intOpen As Integer, intClose As Integer) As Integer
If intOpen = 0 And intClose = 0 Then
SetExit = 0 'Have no records
Exit Function
ElseIf intOpen > 0 And intClose > 0 Then
SetExit = 3 'Have both closed and open records
Exit Function
ElseIf intOpen > 0 And intClose = 0 Then
SetExit = 1 'Have only open records
Exit Function
ElseIf intOpen = 0 And intClose > 0 Then
SetExit = 2 'Have only closed records
End If
End Function
'================================================