• Go to next record without processing current recor (VBA)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Go to next record without processing current recor (VBA)

    Author
    Topic
    #401015

    Consider the following:

    While Not (rst.EOF)
        '1 do somthing here
        
        '2 do something else here
        
        If rst.Field = "X" Then
            'go to the next record without doing any of the next steps
        End If
        
        '3 do a step here
        
        '4 do another step here
        
        rst.next
    Wend

    How can I go to the next record without having steps 3 & 4 executed when the “IF” condition is met?

    Thanks!

    Viewing 1 reply thread
    Author
    Replies
    • #786644

      Do While Not rst.EOF
      ‘1 something
      ‘2 something else
      If Not (rst.Field = “X”) Then
      ‘3 do a step
      ‘4 do another step
      End If
      rst.MoveNext
      Loop

      • #786650

        While that would work, my example was an overly simplistic one.

        I was hoping for something along the lines of Java’s Break or Continue.

        It could be possible to skip to the next record after any of the steps, and there are not only 4 in the real program.

        GOTO would work, but I’d be the black sheep of the VBA world, right? 🙂

      • #786651

        While that would work, my example was an overly simplistic one.

        I was hoping for something along the lines of Java’s Break or Continue.

        It could be possible to skip to the next record after any of the steps, and there are not only 4 in the real program.

        GOTO would work, but I’d be the black sheep of the VBA world, right? 🙂

        • #786674

          No, VBA only has an Exit Do, but that jumps out of the entire Do … Loop construct.

        • #786675

          No, VBA only has an Exit Do, but that jumps out of the entire Do … Loop construct.

    • #786645

      Do While Not rst.EOF
      ‘1 something
      ‘2 something else
      If Not (rst.Field = “X”) Then
      ‘3 do a step
      ‘4 do another step
      End If
      rst.MoveNext
      Loop

    Viewing 1 reply thread
    Reply To: Reply #786675 in Go to next record without processing current recor (VBA)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel