djdidge
asked on
Error: Record Not Found (within a loop that should prevent this)
If Not rsSBSPstuds.EOF Then
rsSBSPstuds.MoveNext
If rsSBSPstuds("S_REF") = lstvStuds.ListItems(p).tex t And _
rsSBSPstuds("SBA_START_DAT E") = lstvStuds.ListItems(p).Sub Items(13) And _
rsSBSPstuds("SBA_END_DATE" ) = lstvStuds.ListItems(p).Sub Items(14) And _
rsSBSPstuds("SBA_SP_REF") = lstvStuds.ListItems(p).Sub Items(17) And _
rsSBSPstuds("SBA_SB_REF") = lstvStuds.ListItems(p).Sub Items(18) Then
If lstvStuds.ListItems(p).Sub Items(18) = "" Then
If rsSBSPstuds("SBA_SB_REF") <> "" Then lstvStuds.ListItems(p).Sub Items(18) = lstvStuds.ListItems(p).Sub Items(18)
End If
If Not rsSBSPstuds.EOF Then rsSBSPstuds.MoveNext
End If
End If
Why does this code run when the if clause should prevent it??... (hope the formatting is ok the word wrap on this little box has made it look dodgy)..
Gary
rsSBSPstuds.MoveNext
If rsSBSPstuds("S_REF") = lstvStuds.ListItems(p).tex
rsSBSPstuds("SBA_START_DAT
rsSBSPstuds("SBA_END_DATE"
rsSBSPstuds("SBA_SP_REF") = lstvStuds.ListItems(p).Sub
rsSBSPstuds("SBA_SB_REF") = lstvStuds.ListItems(p).Sub
If lstvStuds.ListItems(p).Sub
If rsSBSPstuds("SBA_SB_REF") <> "" Then lstvStuds.ListItems(p).Sub
End If
If Not rsSBSPstuds.EOF Then rsSBSPstuds.MoveNext
End If
End If
Why does this code run when the if clause should prevent it??... (hope the formatting is ok the word wrap on this little box has made it look dodgy)..
Gary
Hi djdidge,
You need to change
lstvStuds.ListItems(p).Sub Items(13) & subitems 14
to Date Value first?
You need to change
lstvStuds.ListItems(p).Sub
to Date Value first?
When you are comparing text fields, make sure you filter out all spaces before and after your strings. Also, you could compare the upper case values instead of the original values.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi, try this:
on error resume next
Do While Not rsSBSPstuds.EOF
If rsSBSPstuds("S_REF") = lstvStuds.ListItems(p).tex t And _
rsSBSPstuds("SBA_START_DAT E") = cdate(lstvStuds.ListItems( p).SubItem s(13)) And _
rsSBSPstuds("SBA_END_DATE" ) = cdate(lstvStuds.ListItems( p).SubItem s(14)) And _
rsSBSPstuds("SBA_SP_REF") = lstvStuds.ListItems(p).Sub Items(17) And _
rsSBSPstuds("SBA_SB_REF") = lstvStuds.ListItems(p).Sub Items(18) Then
If lstvStuds.ListItems(p).Sub Items(18) = "" Then
If rsSBSPstuds("SBA_SB_REF") <> "" Then lstvStuds.ListItems(p).Sub Items(18) = lstvStuds.ListItems(p).Sub Items(18)
End If
rsSBSPstuds.MoveNext
End If
Loop
regards.
on error resume next
Do While Not rsSBSPstuds.EOF
If rsSBSPstuds("S_REF") = lstvStuds.ListItems(p).tex
rsSBSPstuds("SBA_START_DAT
rsSBSPstuds("SBA_END_DATE"
rsSBSPstuds("SBA_SP_REF") = lstvStuds.ListItems(p).Sub
rsSBSPstuds("SBA_SB_REF") = lstvStuds.ListItems(p).Sub
If lstvStuds.ListItems(p).Sub
If rsSBSPstuds("SBA_SB_REF") <> "" Then lstvStuds.ListItems(p).Sub
End If
rsSBSPstuds.MoveNext
End If
Loop
regards.
ASKER
I tried your first comment but no joy,
the second wouldn't fit in with my logic as i need to access the next record in the if statements...
Gary
the second wouldn't fit in with my logic as i need to access the next record in the if statements...
Gary
OR
Do While Not rsSBSPstuds.EOF
If rsSBSPstuds("S_REF") = lstvStuds.ListItems(p).tex t And _
rsSBSPstuds("SBA_START_DAT E") = cdate(lstvStuds.ListItems( p).SubItem s(13)) And _
rsSBSPstuds("SBA_END_DATE" ) = cdate(lstvStuds.ListItems( p).SubItem s(14)) And _
rsSBSPstuds("SBA_SP_REF") = lstvStuds.ListItems(p).Sub Items(17) And _
rsSBSPstuds("SBA_SB_REF") = lstvStuds.ListItems(p).Sub Items(18) Then
If lstvStuds.ListItems(p).Sub Items(18) = "" Then
If rsSBSPstuds("SBA_SB_REF") <> "" Then lstvStuds.ListItems(p).Sub Items(18) = lstvStuds.ListItems(p).Sub Items(18)
End If
End If
rsSBSPstuds.MoveNext
Loop
Do While Not rsSBSPstuds.EOF
If rsSBSPstuds("S_REF") = lstvStuds.ListItems(p).tex
rsSBSPstuds("SBA_START_DAT
rsSBSPstuds("SBA_END_DATE"
rsSBSPstuds("SBA_SP_REF") = lstvStuds.ListItems(p).Sub
rsSBSPstuds("SBA_SB_REF") = lstvStuds.ListItems(p).Sub
If lstvStuds.ListItems(p).Sub
If rsSBSPstuds("SBA_SB_REF") <> "" Then lstvStuds.ListItems(p).Sub
End If
End If
rsSBSPstuds.MoveNext
Loop
ASKER
that was directed at "dreamMaster"... i've just seen all your comments appear!..
if rs.eof=false and rs.bof=false then
while rs.eof=False
'your code
rs.MoveNext
wend
end if
while rs.eof=False
'your code
rs.MoveNext
wend
end if
Usually I use a do while construction to loop through a recordset...
So:
If not rsSBSPstuds.eof and not rsSBSPstuds.bof then
do while not rsSBSPstuds.eof
If rsSBSPstuds("S_REF") = lstvStuds.ListItems(p).tex t And _
rsSBSPstuds("SBA_START_DAT E") = lstvStuds.ListItems(p).Sub Items(13) And _
rsSBSPstuds("SBA_END_DATE" ) = lstvStuds.ListItems(p).Sub Items(14) And _
rsSBSPstuds("SBA_SP_REF") = lstvStuds.ListItems(p).Sub Items(17) And _
rsSBSPstuds("SBA_SB_REF") = lstvStuds.ListItems(p).Sub Items(18) Then
If lstvStuds.ListItems(p).Sub Items(18) = "" Then
If rsSBSPstuds("SBA_SB_REF") <> "" Then lstvStuds.ListItems(p).Sub Items(18) = lstvStuds.ListItems(p).Sub Items(18)
End If
end if
rsSBSPstuds.movenext
loop
end if
Cheers,
Max.
So:
If not rsSBSPstuds.eof and not rsSBSPstuds.bof then
do while not rsSBSPstuds.eof
If rsSBSPstuds("S_REF") = lstvStuds.ListItems(p).tex
rsSBSPstuds("SBA_START_DAT
rsSBSPstuds("SBA_END_DATE"
rsSBSPstuds("SBA_SP_REF") = lstvStuds.ListItems(p).Sub
rsSBSPstuds("SBA_SB_REF") = lstvStuds.ListItems(p).Sub
If lstvStuds.ListItems(p).Sub
If rsSBSPstuds("SBA_SB_REF") <> "" Then lstvStuds.ListItems(p).Sub
End If
end if
rsSBSPstuds.movenext
loop
end if
Cheers,
Max.
ASKER
This only needs to run once btw...
ASKER
For p = 1 To srecount
With lstvStuds.ListItems.Add(, , rsSBSPstuds("S_REF"), , "D")
.SubItems(1) = IIf(rsSBSPstuds("s_Forenam e_1") <> "", rsSBSPstuds("s_Forename_1" ), "N/A")
.SubItems(2) = IIf(rsSBSPstuds("s_Surname ") <> "", rsSBSPstuds("s_Surname"), "N/A")
.SubItems(3) = ""
.SubItems(4) = ""
.SubItems(5) = ""
.SubItems(6) = ""
.SubItems(7) = ""
.SubItems(8) = ""
.SubItems(9) = ""
.SubItems(12) = IIf(rsSBSPstuds("S_DATE_OF _BIRTH") <> "", rsSBSPstuds("S_DATE_OF_BIR TH"), "N/A")
.SubItems(13) = IIf(rsSBSPstuds("SBA_START _DATE") <> "", rsSBSPstuds("SBA_START_DAT E"), "N/A")
.SubItems(14) = IIf(rsSBSPstuds("SBA_END_D ATE") <> "", rsSBSPstuds("SBA_END_DATE" ), "N/A")
.SubItems(15) = ""
.SubItems(16) = ""
.SubItems(17) = IIf(rsSBSPstuds("SBA_SP_RE F") <> "", rsSBSPstuds("SBA_SP_REF"), "N/A")
.SubItems(18) = IIf(rsSBSPstuds("SBA_SB_RE F") <> "", rsSBSPstuds("SBA_SB_REF"), "N/A")
.SubItems(19) = ""
.SubItems(20) = ""
.SubItems(21) = IIf(rsSBSPstuds("RESULT") <> "", rsSBSPstuds("RESULT"), "")
.SubItems(22) = ""
.Tag = IIf(flag, &HC0FFC0, &HFFFFFF) ' 'CStr(QBColor(i Mod 10))
If rsSBSPstuds("SBA_STATUS") = "W" Then
lstvStuds.ListItems(p).Sma llIcon = 8
.SubItems(19) = "Yes"
.Tag = RGB(255, 150, 150) '&H8080FF
Else
.SubItems(19) = ""
End If
If flag Then
flag = False
Else
flag = True
End If
End With
On Error Resume Next
Do While Not rsSBSPstuds.EOF
If rsSBSPstuds("S_REF") = lstvStuds.ListItems(p).tex t And _
rsSBSPstuds("SBA_START_DAT E") = CDate(lstvStuds.ListItems( p).SubItem s(13)) And _
rsSBSPstuds("SBA_END_DATE" ) = CDate(lstvStuds.ListItems( p).SubItem s(14)) And _
rsSBSPstuds("SBA_SP_REF") = lstvStuds.ListItems(p).Sub Items(17) And _
rsSBSPstuds("SBA_SB_REF") = lstvStuds.ListItems(p).Sub Items(18) Then
If lstvStuds.ListItems(p).Sub Items(18) = "" Then
If rsSBSPstuds("RESULT") <> "" Then lstvStuds.ListItems(p).Sub Items(18) = rsSBSPstuds("RESULT")
End If
rsSBSPstuds.MoveNext
End If
Loop
'//
Next
A lot of this is irrelevant but it might show more perspective to the problem
With lstvStuds.ListItems.Add(, , rsSBSPstuds("S_REF"), , "D")
.SubItems(1) = IIf(rsSBSPstuds("s_Forenam
.SubItems(2) = IIf(rsSBSPstuds("s_Surname
.SubItems(3) = ""
.SubItems(4) = ""
.SubItems(5) = ""
.SubItems(6) = ""
.SubItems(7) = ""
.SubItems(8) = ""
.SubItems(9) = ""
.SubItems(12) = IIf(rsSBSPstuds("S_DATE_OF
.SubItems(13) = IIf(rsSBSPstuds("SBA_START
.SubItems(14) = IIf(rsSBSPstuds("SBA_END_D
.SubItems(15) = ""
.SubItems(16) = ""
.SubItems(17) = IIf(rsSBSPstuds("SBA_SP_RE
.SubItems(18) = IIf(rsSBSPstuds("SBA_SB_RE
.SubItems(19) = ""
.SubItems(20) = ""
.SubItems(21) = IIf(rsSBSPstuds("RESULT") <> "", rsSBSPstuds("RESULT"), "")
.SubItems(22) = ""
.Tag = IIf(flag, &HC0FFC0, &HFFFFFF) ' 'CStr(QBColor(i Mod 10))
If rsSBSPstuds("SBA_STATUS") = "W" Then
lstvStuds.ListItems(p).Sma
.SubItems(19) = "Yes"
.Tag = RGB(255, 150, 150) '&H8080FF
Else
.SubItems(19) = ""
End If
If flag Then
flag = False
Else
flag = True
End If
End With
On Error Resume Next
Do While Not rsSBSPstuds.EOF
If rsSBSPstuds("S_REF") = lstvStuds.ListItems(p).tex
rsSBSPstuds("SBA_START_DAT
rsSBSPstuds("SBA_END_DATE"
rsSBSPstuds("SBA_SP_REF") = lstvStuds.ListItems(p).Sub
rsSBSPstuds("SBA_SB_REF") = lstvStuds.ListItems(p).Sub
If lstvStuds.ListItems(p).Sub
If rsSBSPstuds("RESULT") <> "" Then lstvStuds.ListItems(p).Sub
End If
rsSBSPstuds.MoveNext
End If
Loop
'//
Next
A lot of this is irrelevant but it might show more perspective to the problem
If it only needs to be run once...you do not need to loop...and you also do not need to use rsSBSPstuds.movenext....
Max.
Max.
ASKER
oops... the bottom bit is what i was trying from ryancys...
ASKER
its already in a bigger loop... the for loop i've pasted up
ASKER
simple logic!
If not rsSBSPstuds.EOF and not rsSBSPstuds.BOF Then
Also, the rsSBSPstuds.movenext will probably be better placed before the last End if...
Max.