?
Solved

Error: Record Not Found (within a loop that should prevent this)

Posted on 2001-08-17
16
Medium Priority
?
175 Views
Last Modified: 2008-03-06
    If Not rsSBSPstuds.EOF Then
     rsSBSPstuds.MoveNext
   
      If rsSBSPstuds("S_REF") = lstvStuds.ListItems(p).text And _
         rsSBSPstuds("SBA_START_DATE") = lstvStuds.ListItems(p).SubItems(13) And _
         rsSBSPstuds("SBA_END_DATE") = lstvStuds.ListItems(p).SubItems(14) And _
         rsSBSPstuds("SBA_SP_REF") = lstvStuds.ListItems(p).SubItems(17) And _
         rsSBSPstuds("SBA_SB_REF") = lstvStuds.ListItems(p).SubItems(18) Then
         
         If lstvStuds.ListItems(p).SubItems(18) = "" Then
            If rsSBSPstuds("SBA_SB_REF") <> "" Then lstvStuds.ListItems(p).SubItems(18) = lstvStuds.ListItems(p).SubItems(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
0
Comment
Question by:djdidge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 3
  • +3
16 Comments
 
LVL 19

Expert Comment

by:DreamMaster
ID: 6396718
Try:

If not rsSBSPstuds.EOF and not rsSBSPstuds.BOF Then

Also, the rsSBSPstuds.movenext will probably be better placed before the last End if...

Max.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6396723
Hi djdidge,

You need to change

lstvStuds.ListItems(p).SubItems(13) & subitems 14

to Date Value first?
0
 
LVL 11

Expert Comment

by:Otana
ID: 6396724
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 43

Accepted Solution

by:
TimCottee earned 200 total points
ID: 6396727
On your last record in the recordset, you test If Not .Eof which will return false, you then movenext which will move you past the end of the recordset and then your if statement references rsSBSPstuds("SBA_SB_REF") later on. This will give record not found as you are at EOF due to the earlier movenext on the last record.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6396728
Hi, try this:

on error resume next

Do While Not rsSBSPstuds.EOF  
     If rsSBSPstuds("S_REF") = lstvStuds.ListItems(p).text And _
        rsSBSPstuds("SBA_START_DATE") = cdate(lstvStuds.ListItems(p).SubItems(13)) And _
        rsSBSPstuds("SBA_END_DATE") = cdate(lstvStuds.ListItems(p).SubItems(14)) And _
        rsSBSPstuds("SBA_SP_REF") = lstvStuds.ListItems(p).SubItems(17) And _
        rsSBSPstuds("SBA_SB_REF") = lstvStuds.ListItems(p).SubItems(18) Then
       
        If lstvStuds.ListItems(p).SubItems(18) = "" Then
           If rsSBSPstuds("SBA_SB_REF") <> "" Then lstvStuds.ListItems(p).SubItems(18) = lstvStuds.ListItems(p).SubItems(18)
        End If
       
        rsSBSPstuds.MoveNext
     End If
Loop


regards.
0
 
LVL 2

Author Comment

by:djdidge
ID: 6396741
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
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6396743
OR

Do While Not rsSBSPstuds.EOF  
    If rsSBSPstuds("S_REF") = lstvStuds.ListItems(p).text And _
       rsSBSPstuds("SBA_START_DATE") = cdate(lstvStuds.ListItems(p).SubItems(13)) And _
       rsSBSPstuds("SBA_END_DATE") = cdate(lstvStuds.ListItems(p).SubItems(14)) And _
       rsSBSPstuds("SBA_SP_REF") = lstvStuds.ListItems(p).SubItems(17) And _
       rsSBSPstuds("SBA_SB_REF") = lstvStuds.ListItems(p).SubItems(18) Then
       
       If lstvStuds.ListItems(p).SubItems(18) = "" Then
          If rsSBSPstuds("SBA_SB_REF") <> "" Then lstvStuds.ListItems(p).SubItems(18) = lstvStuds.ListItems(p).SubItems(18)
       End If
       
    End If
    rsSBSPstuds.MoveNext

Loop
0
 
LVL 2

Author Comment

by:djdidge
ID: 6396746
that was directed at "dreamMaster"... i've just seen all your comments appear!..
0
 
LVL 1

Expert Comment

by:harsh008_k
ID: 6396753
if rs.eof=false and rs.bof=false then
  while rs.eof=False
       'your code
       rs.MoveNext
  wend
end if
0
 
LVL 19

Expert Comment

by:DreamMaster
ID: 6396771
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).text And _
        rsSBSPstuds("SBA_START_DATE") = lstvStuds.ListItems(p).SubItems(13) And _
        rsSBSPstuds("SBA_END_DATE") = lstvStuds.ListItems(p).SubItems(14) And _
        rsSBSPstuds("SBA_SP_REF") = lstvStuds.ListItems(p).SubItems(17) And _
        rsSBSPstuds("SBA_SB_REF") = lstvStuds.ListItems(p).SubItems(18) Then
       
        If lstvStuds.ListItems(p).SubItems(18) = "" Then
           If rsSBSPstuds("SBA_SB_REF") <> "" Then lstvStuds.ListItems(p).SubItems(18) = lstvStuds.ListItems(p).SubItems(18)
        End If
    end if
    rsSBSPstuds.movenext
   loop
end if

Cheers,
Max.
0
 
LVL 2

Author Comment

by:djdidge
ID: 6396774
This only needs to run once btw...
0
 
LVL 2

Author Comment

by:djdidge
ID: 6396782
    For p = 1 To srecount
      With lstvStuds.ListItems.Add(, , rsSBSPstuds("S_REF"), , "D")
        .SubItems(1) = IIf(rsSBSPstuds("s_Forename_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_BIRTH"), "N/A")
        .SubItems(13) = IIf(rsSBSPstuds("SBA_START_DATE") <> "", rsSBSPstuds("SBA_START_DATE"), "N/A")
        .SubItems(14) = IIf(rsSBSPstuds("SBA_END_DATE") <> "", rsSBSPstuds("SBA_END_DATE"), "N/A")
        .SubItems(15) = ""
        .SubItems(16) = ""
        .SubItems(17) = IIf(rsSBSPstuds("SBA_SP_REF") <> "", rsSBSPstuds("SBA_SP_REF"), "N/A")
        .SubItems(18) = IIf(rsSBSPstuds("SBA_SB_REF") <> "", 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).SmallIcon = 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).text And _
       rsSBSPstuds("SBA_START_DATE") = CDate(lstvStuds.ListItems(p).SubItems(13)) And _
       rsSBSPstuds("SBA_END_DATE") = CDate(lstvStuds.ListItems(p).SubItems(14)) And _
       rsSBSPstuds("SBA_SP_REF") = lstvStuds.ListItems(p).SubItems(17) And _
       rsSBSPstuds("SBA_SB_REF") = lstvStuds.ListItems(p).SubItems(18) Then
       
       If lstvStuds.ListItems(p).SubItems(18) = "" Then
          If rsSBSPstuds("RESULT") <> "" Then lstvStuds.ListItems(p).SubItems(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
0
 
LVL 19

Expert Comment

by:DreamMaster
ID: 6396785
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.
0
 
LVL 2

Author Comment

by:djdidge
ID: 6396786
oops... the bottom bit is what i was trying from ryancys...
0
 
LVL 2

Author Comment

by:djdidge
ID: 6396789
its already in a bigger loop... the for loop i've pasted up
0
 
LVL 2

Author Comment

by:djdidge
ID: 6396935
simple logic!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question