PC Review


Reply
Thread Tools Rate Thread

stuck in a loop

 
 
Joseph Atie
Guest
Posts: n/a
 
      16th Sep 2009
im trying to iterate through 2 recordsets.

the 2 recordsets contain data from 2 tables with a 1(rs1) to many (rs2)
relationship.

so the idea is for each loop of rs1 there should be serveral loops of rs2.

but im stuck inside my loops and cant seem to find a way out.

help please

Set rs1 = CurrentDb.OpenRecordset(qry1)
'loop through transaction codes and check if items have been returned
If Not (rs1.BOF And rs1.EOF) Then
rs1.MoveFirst
Do While Not rs1.EOF
'set closed to catch open record
closed = True
'collect transcode from recordset and search transdata
tcode = rs1.Fields("transcode")
qry2 = "SELECT Transdata.Transcode, Transdata.[In] FROM Transdata
WHERE Transdata.Transcode= " & tcode & ";"
Set rs2 = CurrentDb.OpenRecordset(qry2)
If Not (rs2.BOF And rs2.EOF) Then
rs2.MoveFirst
'loop through transdata for each transaction code, set closed to
true if open record found
Do While Not rs2.EOF
If IsNull(rs2.Fields("in")) Then
closed = False
rs2.MoveLast
Else
rs2.MoveNext
End If
Loop
End If
If closed = True Then
rs1.Edit
rs1.Fields("in date") = Date
rs1.Update
rs1.MoveNext
End If
Loop
End If
 
Reply With Quote
 
 
 
 
Paolo
Guest
Posts: n/a
 
      16th Sep 2009
Hi Joseph Atie,

you movenext the rs1 just when closed= true but if IsNull(rs2.Fields("in"))
you put closed =false and you movelast the rs2 so you end this loop and so
you don't movenext the rs1 and you enter again the first loop with the same
value for tcode and so the rs2 will be the same so you'll never end this
loop. You have to check the exit logic of your loop.

HTH Paolo

"Joseph Atie" wrote:

> im trying to iterate through 2 recordsets.
>
> the 2 recordsets contain data from 2 tables with a 1(rs1) to many (rs2)
> relationship.
>
> so the idea is for each loop of rs1 there should be serveral loops of rs2.
>
> but im stuck inside my loops and cant seem to find a way out.
>
> help please
>
> Set rs1 = CurrentDb.OpenRecordset(qry1)
> 'loop through transaction codes and check if items have been returned
> If Not (rs1.BOF And rs1.EOF) Then
> rs1.MoveFirst
> Do While Not rs1.EOF
> 'set closed to catch open record
> closed = True
> 'collect transcode from recordset and search transdata
> tcode = rs1.Fields("transcode")
> qry2 = "SELECT Transdata.Transcode, Transdata.[In] FROM Transdata
> WHERE Transdata.Transcode= " & tcode & ";"
> Set rs2 = CurrentDb.OpenRecordset(qry2)
> If Not (rs2.BOF And rs2.EOF) Then
> rs2.MoveFirst
> 'loop through transdata for each transaction code, set closed to
> true if open record found
> Do While Not rs2.EOF
> If IsNull(rs2.Fields("in")) Then
> closed = False
> rs2.MoveLast
> Else
> rs2.MoveNext
> End If
> Loop
> End If
> If closed = True Then
> rs1.Edit
> rs1.Fields("in date") = Date
> rs1.Update
> rs1.MoveNext
> End If
> Loop
> End If

 
Reply With Quote
 
Dale Fye
Guest
Posts: n/a
 
      16th Sep 2009
What Paolo is trying to say is that your last few lines should look like:

If closed = True Then
rs1.Edit
rs1.Fields("in date") = Date
rs1.Update
End If
'the following line was move from inside the If/EndIf to outside it
rs1.MoveNext
Loop
End If

----
HTH
Dale



"Paolo" wrote:

> Hi Joseph Atie,
>
> you movenext the rs1 just when closed= true but if IsNull(rs2.Fields("in"))
> you put closed =false and you movelast the rs2 so you end this loop and so
> you don't movenext the rs1 and you enter again the first loop with the same
> value for tcode and so the rs2 will be the same so you'll never end this
> loop. You have to check the exit logic of your loop.
>
> HTH Paolo
>
> "Joseph Atie" wrote:
>
> > im trying to iterate through 2 recordsets.
> >
> > the 2 recordsets contain data from 2 tables with a 1(rs1) to many (rs2)
> > relationship.
> >
> > so the idea is for each loop of rs1 there should be serveral loops of rs2.
> >
> > but im stuck inside my loops and cant seem to find a way out.
> >
> > help please
> >
> > Set rs1 = CurrentDb.OpenRecordset(qry1)
> > 'loop through transaction codes and check if items have been returned
> > If Not (rs1.BOF And rs1.EOF) Then
> > rs1.MoveFirst
> > Do While Not rs1.EOF
> > 'set closed to catch open record
> > closed = True
> > 'collect transcode from recordset and search transdata
> > tcode = rs1.Fields("transcode")
> > qry2 = "SELECT Transdata.Transcode, Transdata.[In] FROM Transdata
> > WHERE Transdata.Transcode= " & tcode & ";"
> > Set rs2 = CurrentDb.OpenRecordset(qry2)
> > If Not (rs2.BOF And rs2.EOF) Then
> > rs2.MoveFirst
> > 'loop through transdata for each transaction code, set closed to
> > true if open record found
> > Do While Not rs2.EOF
> > If IsNull(rs2.Fields("in")) Then
> > closed = False
> > rs2.MoveLast
> > Else
> > rs2.MoveNext
> > End If
> > Loop
> > End If
> > If closed = True Then
> > rs1.Edit
> > rs1.Fields("in date") = Date
> > rs1.Update
> > rs1.MoveNext
> > End If
> > Loop
> > End If

 
Reply With Quote
 
Paolo
Guest
Posts: n/a
 
      16th Sep 2009
Thanx Dale,
your explanation is more readable than mine but well, I wrote it this
morning before my coffee...

"Dale Fye" wrote:

> What Paolo is trying to say is that your last few lines should look like:
>
> If closed = True Then
> rs1.Edit
> rs1.Fields("in date") = Date
> rs1.Update
> End If
> 'the following line was move from inside the If/EndIf to outside it
> rs1.MoveNext
> Loop
> End If
>
> ----
> HTH
> Dale
>
>
>
> "Paolo" wrote:
>
> > Hi Joseph Atie,
> >
> > you movenext the rs1 just when closed= true but if IsNull(rs2.Fields("in"))
> > you put closed =false and you movelast the rs2 so you end this loop and so
> > you don't movenext the rs1 and you enter again the first loop with the same
> > value for tcode and so the rs2 will be the same so you'll never end this
> > loop. You have to check the exit logic of your loop.
> >
> > HTH Paolo
> >
> > "Joseph Atie" wrote:
> >
> > > im trying to iterate through 2 recordsets.
> > >
> > > the 2 recordsets contain data from 2 tables with a 1(rs1) to many (rs2)
> > > relationship.
> > >
> > > so the idea is for each loop of rs1 there should be serveral loops of rs2.
> > >
> > > but im stuck inside my loops and cant seem to find a way out.
> > >
> > > help please
> > >
> > > Set rs1 = CurrentDb.OpenRecordset(qry1)
> > > 'loop through transaction codes and check if items have been returned
> > > If Not (rs1.BOF And rs1.EOF) Then
> > > rs1.MoveFirst
> > > Do While Not rs1.EOF
> > > 'set closed to catch open record
> > > closed = True
> > > 'collect transcode from recordset and search transdata
> > > tcode = rs1.Fields("transcode")
> > > qry2 = "SELECT Transdata.Transcode, Transdata.[In] FROM Transdata
> > > WHERE Transdata.Transcode= " & tcode & ";"
> > > Set rs2 = CurrentDb.OpenRecordset(qry2)
> > > If Not (rs2.BOF And rs2.EOF) Then
> > > rs2.MoveFirst
> > > 'loop through transdata for each transaction code, set closed to
> > > true if open record found
> > > Do While Not rs2.EOF
> > > If IsNull(rs2.Fields("in")) Then
> > > closed = False
> > > rs2.MoveLast
> > > Else
> > > rs2.MoveNext
> > > End If
> > > Loop
> > > End If
> > > If closed = True Then
> > > rs1.Edit
> > > rs1.Fields("in date") = Date
> > > rs1.Update
> > > rs1.MoveNext
> > > End If
> > > Loop
> > > End If

 
Reply With Quote
 
Joseph Atie
Guest
Posts: n/a
 
      16th Sep 2009
Thanks very much guys

silly mistake on my part.

"Paolo" wrote:

> Thanx Dale,
> your explanation is more readable than mine but well, I wrote it this
> morning before my coffee...
>
> "Dale Fye" wrote:
>
> > What Paolo is trying to say is that your last few lines should look like:
> >
> > If closed = True Then
> > rs1.Edit
> > rs1.Fields("in date") = Date
> > rs1.Update
> > End If
> > 'the following line was move from inside the If/EndIf to outside it
> > rs1.MoveNext
> > Loop
> > End If
> >
> > ----
> > HTH
> > Dale
> >
> >
> >
> > "Paolo" wrote:
> >
> > > Hi Joseph Atie,
> > >
> > > you movenext the rs1 just when closed= true but if IsNull(rs2.Fields("in"))
> > > you put closed =false and you movelast the rs2 so you end this loop and so
> > > you don't movenext the rs1 and you enter again the first loop with the same
> > > value for tcode and so the rs2 will be the same so you'll never end this
> > > loop. You have to check the exit logic of your loop.
> > >
> > > HTH Paolo
> > >
> > > "Joseph Atie" wrote:
> > >
> > > > im trying to iterate through 2 recordsets.
> > > >
> > > > the 2 recordsets contain data from 2 tables with a 1(rs1) to many (rs2)
> > > > relationship.
> > > >
> > > > so the idea is for each loop of rs1 there should be serveral loops of rs2.
> > > >
> > > > but im stuck inside my loops and cant seem to find a way out.
> > > >
> > > > help please
> > > >
> > > > Set rs1 = CurrentDb.OpenRecordset(qry1)
> > > > 'loop through transaction codes and check if items have been returned
> > > > If Not (rs1.BOF And rs1.EOF) Then
> > > > rs1.MoveFirst
> > > > Do While Not rs1.EOF
> > > > 'set closed to catch open record
> > > > closed = True
> > > > 'collect transcode from recordset and search transdata
> > > > tcode = rs1.Fields("transcode")
> > > > qry2 = "SELECT Transdata.Transcode, Transdata.[In] FROM Transdata
> > > > WHERE Transdata.Transcode= " & tcode & ";"
> > > > Set rs2 = CurrentDb.OpenRecordset(qry2)
> > > > If Not (rs2.BOF And rs2.EOF) Then
> > > > rs2.MoveFirst
> > > > 'loop through transdata for each transaction code, set closed to
> > > > true if open record found
> > > > Do While Not rs2.EOF
> > > > If IsNull(rs2.Fields("in")) Then
> > > > closed = False
> > > > rs2.MoveLast
> > > > Else
> > > > rs2.MoveNext
> > > > End If
> > > > Loop
> > > > End If
> > > > If closed = True Then
> > > > rs1.Edit
> > > > rs1.Fields("in date") = Date
> > > > rs1.Update
> > > > rs1.MoveNext
> > > > End If
> > > > Loop
> > > > End If

 
Reply With Quote
 
Dale Fye
Guest
Posts: n/a
 
      17th Sep 2009
Ha!

Like I've never forgotten to put a rs.movenext at the bottom of a loop.

Actually, If I remember correctly, I did this same thing just the other day.

Dale

"Joseph Atie" <(E-Mail Removed)> wrote in message
news:00F38260-25F1-4153-903C-(E-Mail Removed)...
> Thanks very much guys
>
> silly mistake on my part.
>
> "Paolo" wrote:
>
>> Thanx Dale,
>> your explanation is more readable than mine but well, I wrote it this
>> morning before my coffee...
>>
>> "Dale Fye" wrote:
>>
>> > What Paolo is trying to say is that your last few lines should look
>> > like:
>> >
>> > If closed = True Then
>> > rs1.Edit
>> > rs1.Fields("in date") = Date
>> > rs1.Update
>> > End If
>> > 'the following line was move from inside the If/EndIf to outside it
>> > rs1.MoveNext
>> > Loop
>> > End If
>> >
>> > ----
>> > HTH
>> > Dale
>> >
>> >
>> >
>> > "Paolo" wrote:
>> >
>> > > Hi Joseph Atie,
>> > >
>> > > you movenext the rs1 just when closed= true but if
>> > > IsNull(rs2.Fields("in"))
>> > > you put closed =false and you movelast the rs2 so you end this loop
>> > > and so
>> > > you don't movenext the rs1 and you enter again the first loop with
>> > > the same
>> > > value for tcode and so the rs2 will be the same so you'll never end
>> > > this
>> > > loop. You have to check the exit logic of your loop.
>> > >
>> > > HTH Paolo
>> > >
>> > > "Joseph Atie" wrote:
>> > >
>> > > > im trying to iterate through 2 recordsets.
>> > > >
>> > > > the 2 recordsets contain data from 2 tables with a 1(rs1) to many
>> > > > (rs2)
>> > > > relationship.
>> > > >
>> > > > so the idea is for each loop of rs1 there should be serveral loops
>> > > > of rs2.
>> > > >
>> > > > but im stuck inside my loops and cant seem to find a way out.
>> > > >
>> > > > help please
>> > > >
>> > > > Set rs1 = CurrentDb.OpenRecordset(qry1)
>> > > > 'loop through transaction codes and check if items have been
>> > > > returned
>> > > > If Not (rs1.BOF And rs1.EOF) Then
>> > > > rs1.MoveFirst
>> > > > Do While Not rs1.EOF
>> > > > 'set closed to catch open record
>> > > > closed = True
>> > > > 'collect transcode from recordset and search transdata
>> > > > tcode = rs1.Fields("transcode")
>> > > > qry2 = "SELECT Transdata.Transcode, Transdata.[In] FROM
>> > > > Transdata
>> > > > WHERE Transdata.Transcode= " & tcode & ";"
>> > > > Set rs2 = CurrentDb.OpenRecordset(qry2)
>> > > > If Not (rs2.BOF And rs2.EOF) Then
>> > > > rs2.MoveFirst
>> > > > 'loop through transdata for each transaction code, set
>> > > > closed to
>> > > > true if open record found
>> > > > Do While Not rs2.EOF
>> > > > If IsNull(rs2.Fields("in")) Then
>> > > > closed = False
>> > > > rs2.MoveLast
>> > > > Else
>> > > > rs2.MoveNext
>> > > > End If
>> > > > Loop
>> > > > End If
>> > > > If closed = True Then
>> > > > rs1.Edit
>> > > > rs1.Fields("in date") = Date
>> > > > rs1.Update
>> > > > rs1.MoveNext
>> > > > End If
>> > > > Loop
>> > > > End If



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XP stuck in loop cy Windows XP General 4 21st Apr 2009 10:14 PM
HELP - Stuck in loop gti_jobert Microsoft Excel Programming 3 27th Apr 2006 02:41 PM
Stuck in a loop =?Utf-8?B?Um9zcw==?= Windows XP General 1 20th Jan 2006 07:29 AM
Stuck in a loop =?Utf-8?B?Um9zcw==?= Windows XP General 3 13th Jan 2005 07:06 AM
Stuck in a loop Wentworth Windows XP General 4 30th Oct 2003 02:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:21 AM.