"Kevin Robinson" <k.s.robinson.DeleteThis@btinternet.com> wrote in
news:cv2p4l$2nf$1@titan.btinternet.com:
> I hope that someone can help with a this problem:
>
> I have a table containing 5 different records and I want to print out
> only those records which met a given condition.
>
> My code is similar to this where mydata1,2 and 3 represent data held
> in 3 different rows in the 5 row table.:
>
> With rsTemp
> .movefirst
> Do While Not .EOF
> if condition1 = true then
> print #1 mydata1
> else if condition2 = true then
> print #1 mydata2
> else if condition3 = true then
> print #1 mydata3
> end if
> .movenext
> loop
> end with
>
> The problem is that some of the same rows print out more than once so
> I end up with 15 rows and not the three
> distinct rows expected from he code..
> How can I control this using if then statements within a loop? Or is
> there an alternative approach to this
> problem?
>
> Regards
>
> Kevin
>
>
>
Hi Kevin. You don't say what condition1, condition2, and condition3 are.
Are they boolean variables? If so, I assume that their values are set at
some point in your code before your loop begins? If so, then then their
value does not depend on anything in your recordset, so for each
condition that is true, all five records will be printed. In fact, since
you say 15 rows are printed, it's pretty clear that all three conditions
are true.
If on the other hand condition1, condition2, and condition3 are functions
or expressions, evaluated afresh at each point in your loop, then if you
are expecting three records but are getting 15, there is something wrong
with the way that your code is evaluating them.
I think you need to explain a bit more about these conditions in order
for anyone to pinpoint what is wrong.
Regards
Rob<!-- ~MESSAGE_AFTER~ -->
>> Stay informed about: VB6 Navigating Recordsets