Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 23rd, 2006, 11:01 AM
Friend of Wrox
 
Join Date: May 2006
Location: Jonesboro, AR, USA.
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
Reply With Quote
  #2 (permalink)  
Old October 24th, 2006, 08:45 AM
pjm pjm is offline
Authorized User
 
Join Date: Jul 2006
Location: Boston, MA, USA.
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-
Reply With Quote
  #3 (permalink)  
Old October 24th, 2006, 03:56 PM
Friend of Wrox
 
Join Date: May 2006
Location: Jonesboro, AR, USA.
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.


Reply With Quote
  #4 (permalink)  
Old October 26th, 2006, 10:22 AM
Friend of Wrox
 
Join Date: May 2006
Location: Jonesboro, AR, USA.
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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:56 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.