Results 1 to 4 of 4

Thread: Loop error

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    9

    Loop error

    Code:
    For j = lvOrderList.ListItems.Count To 1 Step -1
    
            If rsProducts!Product_ID = lvOrderList.ListItems(j).Text Then
                Do
                    orderQnty = lvOrderList.ListItems(j).ListSubItems(2).Text
                    rsProducts.Edit
                    rsProducts!Units_InStock = rsProducts!Units_InStock + orderQnty
                    rsProducts.Update
    
                Loop Until rsProducts.EOF
    
            Next j
    next without for error
    Last edited by si_the_geek; Feb 23rd, 2011 at 10:41 AM. Reason: added Code tags

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Loop error

    When you post code please put it inside code tags so it is displayed in a more readable way - either using the Code/VBCode buttons in the post editor screen (or at the top of the Quick Reply box), or by putting them in manually, like this: [code] code here [/code] . I have added them to your post.


    The error is actually telling you the wrong thing, but that is due to a surprising level of complexity for VB to deal with.

    The problem is that a control structure (For-Next / Do-Loop / If - End If / ...) has been opened but not closed (or closed without being opened, but that does not apply here).

    This is one of the many cases where indenting your code helps, as you should easily be able to spot which one is causing the issue.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    9

    Re: Loop error

    Added the end if but still does not loop through to get
    rsProducts!Product_ID = lvOrderList.ListItems(j).Text

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Loop error

    It isn't clear what you mean by that, but I can see issues with your code... a big one being the Do-Loop not having a way out (you don't change record inside it, so how can .EOF change?)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width