Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 23rd, 2006, 11:01 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default skipping records while looping


Hello once again,
I'm trying to loop through the table(below). I've written the code that loops through a table that has three levels, but this new table has 4 levels. I need to loop through this table while totally ignoring the records on level 4. Any ideas how I might accomplish this?

Thanks,
Dave

Code:
rsRev.MoveFirst
While Not rsRev.EOF And Not rs4Loc.EOF

    sBreak = rsRev.Fields("[BREAKPT]").Value
    sLoc = rs4Loc.Fields("[location]").Value
    iLevel = rs4Loc.Fields("[level]").Value

    rsRev.Edit
    rsRev.Fields("[LOC SEQ]").Value = iLevel
    rsRev![Location] = sLoc
    rsRev.Update
    rsRev.MoveNext
    If sBreak = "T" Then
        rs4Loc.Move 3
    ElseIf sBreak = "D" Then
        rs4Loc.Move 2
    Else
        rs4Loc.MoveNext
    End If
Wend
Code:
location    level
11ALR001    1
11ALR001    2
11ALR001    3
11ALR001    4
11ALR002    4
11ALR002    3
11ALR002    2
11ALR002    1
11ALR003    1
11ALR003    2
11ALR003    3
11ALR003    4
11ALR004    4
11ALR004    3
11ALR004    2
11ALR004    1
11ALR005    1
11ALR005    2
11ALR005    3
11ALR005    4
 
Old October 24th, 2006, 08:45 AM
pjm pjm is offline
Authorized User
 
Join Date: Jul 2006
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just put your processing code inside an if statement:

if iLevel <> 4 then
    rsRev.Edit
    rsRev.Fields("[LOC SEQ]").Value = iLevel
    rsRev![Location] = sLoc
    rsRev.Update
    rsRev.MoveNext
    If sBreak = "T" Then
        rs4Loc.Move 3
    ElseIf sBreak = "D" Then
        rs4Loc.Move 2
    Else
        rs4Loc.MoveNext
    End If
End If

-Phil-
 
Old October 24th, 2006, 03:56 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply Phil!
Unfortunately I don't think it is that simple.

  
Code:
If sBreak = "T" Then
Code:
        rs4Loc.Move 3
    ElseIf sBreak = "D" Then
        rs4Loc.Move 2
    Else
        rs4Loc.MoveNext
    End If


Even inside this piece of code I need 4 to be skipped. So, if I used the <>4 if statement it might weed out some 4's, but not all. Because if say there's a level 3 that passes the <>4 test then it gets inside the statement. If sBreak = T then it would move from 3-4-4 and end up on the next 3. I need it to start at 3 skip 4 skip 4 -3-2 and end on 1.


 
Old October 26th, 2006, 10:22 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I got it working. Not exactly the way I wanted, but it works. I made a new table and made a query that copied the records that were being looped through to it. Then I made a query that would delete all the rows that were level 4. That way I didn't have to skip the 4's, they weren't even there.






Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView - Skipping a Row gothael ASP.NET 2.0 Basics 1 July 18th, 2008 10:02 AM
Looping through all records in excel? dhl365 Pro VB 6 1 July 26th, 2005 03:39 PM
Looping through subform records V Access VBA 8 April 20th, 2004 08:10 AM
where is cursor after looping through records? monstermash Classic ASP Basics 7 July 22nd, 2003 03:55 AM
looping through return records in sproc jtyson SQL Server ASP 5 July 14th, 2003 10:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.