Need a little help figuring where my error is in this code. Please take a look, I can't see it.
this code finds the case that matches the criteria, then determines if the charge sentence is to run concurrently or consecutively, if concurrent give me the highest sentence of all the sentences for the case, if consecutive then add them to the concurrent sentence for a total years
Private Sub Report_Open(Cancel As Integer)
Dim TotalMonths As Long
Dim SubTotal As Long
Dim TotalDays As Long
Dim Sent As Long
Dim rstDefCharge As Recordset
Dim rstConCons As Recordset
Dim db As DAO.Database
Dim TotalYears As Integer
Set db = DBEngine(0)(0)
Set rstConCons = db.OpenRecordset("Select * from tblConcurentConsecutiveTable where PrimaryCaseNo = tblDefChargesSentence!CaseNo and ((tblConsecutiveTable!DefendantId) = '" & (DefendantId) & "')", dbOpenSnapshot)
Set rstDefCharge = db.OpenRecordset("Select * from tblDefChargesSentence where tblConcurentConsecutiveTable!PrimaryCaseNo = tblDefChargesSentence!CaseNo and ((tblConsecutiveTable!DefendantId) = '" & (DefendantId) & "'))", dbOpenSnapshot)
DoCmd.SetWarnings (off)
SubTotal = 0
With rstConCons
Do Until .EOF
If tblConcurentConsecutiveTable![ConConsecCaseNo] = tblDefChargesSentence![CaseNo] Then
If tblDefChargesSentence!ConcurrentSentence = True Then
TotalMonths = tblDefChargesSentence!SentYrs * 12
TotalDays = tblDefChargesSentence!SentDays / 30
If TotalMonths > tblDefChargesSentence!SentMos Then
If TotalMonths > TotalDays Then
Sent = TotalMonths / 12
If Sent > SubTotal Then
SubTotal = Sent
End If
End If
End If
End If
End If
.MoveNext
Loop
Do Until .EOF
If tblConcurentConsecutiveTable!ConConsecCaseNo = tblDefChargesSentence!CaseNo Then
If tblDefChargesSentence!ConsecutiveSentence = True Then
SubTotal = tblDefChargesSentence!SentYrs + SubTotal
End If
End If
.MoveNext
Loop
TotalYears = SubTotal
End With
End Sub
this code finds the case that matches the criteria, then determines if the charge sentence is to run concurrently or consecutively, if concurrent give me the highest sentence of all the sentences for the case, if consecutive then add them to the concurrent sentence for a total years
Private Sub Report_Open(Cancel As Integer)
Dim TotalMonths As Long
Dim SubTotal As Long
Dim TotalDays As Long
Dim Sent As Long
Dim rstDefCharge As Recordset
Dim rstConCons As Recordset
Dim db As DAO.Database
Dim TotalYears As Integer
Set db = DBEngine(0)(0)
Set rstConCons = db.OpenRecordset("Select * from tblConcurentConsecutiveTable where PrimaryCaseNo = tblDefChargesSentence!CaseNo and ((tblConsecutiveTable!DefendantId) = '" & (DefendantId) & "')", dbOpenSnapshot)
Set rstDefCharge = db.OpenRecordset("Select * from tblDefChargesSentence where tblConcurentConsecutiveTable!PrimaryCaseNo = tblDefChargesSentence!CaseNo and ((tblConsecutiveTable!DefendantId) = '" & (DefendantId) & "'))", dbOpenSnapshot)
DoCmd.SetWarnings (off)
SubTotal = 0
With rstConCons
Do Until .EOF
If tblConcurentConsecutiveTable![ConConsecCaseNo] = tblDefChargesSentence![CaseNo] Then
If tblDefChargesSentence!ConcurrentSentence = True Then
TotalMonths = tblDefChargesSentence!SentYrs * 12
TotalDays = tblDefChargesSentence!SentDays / 30
If TotalMonths > tblDefChargesSentence!SentMos Then
If TotalMonths > TotalDays Then
Sent = TotalMonths / 12
If Sent > SubTotal Then
SubTotal = Sent
End If
End If
End If
End If
End If
.MoveNext
Loop
Do Until .EOF
If tblConcurentConsecutiveTable!ConConsecCaseNo = tblDefChargesSentence!CaseNo Then
If tblDefChargesSentence!ConsecutiveSentence = True Then
SubTotal = tblDefChargesSentence!SentYrs + SubTotal
End If
End If
.MoveNext
Loop
TotalYears = SubTotal
End With
End Sub