Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

objRS.moveNext issues 1

Status
Not open for further replies.

onressy

Programmer
Mar 7, 2006
421
CA
Hi, I have a:

Do Until objRS.EOF
....
.....

objRS.moveNext
Loop

I would like to skip the records if a condition is met, something like so:

Do Until objRS.EOF

If portal=1000 Then
Dim names
names = names & "|" & objRS("ProductName")
' below I would like to skip the look to the next recode if name is already in the string?
If InStrRev(names,objRS("ProductName"))>0 Then
objRS.moveNext
End If
End If
....
.....

objRS.moveNext
Loop

If portal=1000 Then
Dim names
names = names & "|" & objRS("ProductName")
If InStrRev(names,objRS("ProductName"))>0 Then
'objRS.moveNext
'Loop
End If
End If
 
Just do a while loop in your loop area until you hit a condition to continue:
Code:
      If InStrRev(names,objRS("ProductName"))>0 Then 
         Do While InStrRev(names,objRS("ProductName")) > 0  
            objRS.moveNext
         Loop
      End If
 
monksnake: Bam, Either EOF or BOF is True - you need another EOF check if your going to loop like that :)

Suggested solution 1: Change your query to SELECT DISTINCT for the field you need, let the database do the work.

I had a second suggestion, but I don't understand what your doing. Or rather, I don't understand your explanation of what your doing inlight of what your code is doing. it looks like your checking a variable to be 1000, then adding a product number to a string, then if the product number you just added is in that string you want to skip the next product number that you haven't looked at yet...? Basically what this code will do is create a list of every other product number in your query, regardless of repeats and regardles of any unique values in the odd records.

if all your trying to do is build a unique list of items from the query (and you don't want to change the query) then you should be doing the check befoe you add the value to the string. So:
Code:
Dim names
Do Until objRS.EOF
    If portal=1000 Then
        If InStr(names, objRS("Productname")) = 0 Then
            names = names & "|" & objRS("ProductName")

            '... additional logic for this unique part number
        End If
    End If
objRS.moveNext
Loop
I didn't even notice it until afterwards, but your re-dimming your "names" variable on every loop...

 
monksnake: Bam, Either EOF or BOF is True - you need another EOF check if your going to loop like that :)

Yeah, you're right, brain fart.
I've had to do loops like this many times through recordsets and I normally don't screw up like that.

Code:
Do While !objRS.EOF AND InStrRev(names,objRS("ProductName")) > 0 OR (EOF CHECK!!!)
 
I just wish MS would've upgraded ASP to include the "Bam" in the EOF/BOF error message :p

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top