Why can't I "Exit While"?

Posted on 2003-03-31
Medium Priority
Last Modified: 2012-08-13
Fairly self-explanitory and I'm sure an easy question.  Example:

while rsTest.EOF = False
    if rsTest!id = 1 then exit while

According to Microsoft, from the MSDN VB6 reference for the "Exit" keyword:

Immediately exits the While loop in which it appears. Execution continues with the statement following the End While statement...."

So why, when I use "Exit While" does VB say "Syntax Error"?  If I can't use it (why would MS say I can?) what alternative can I use?  (I hate goto's but will use them if I have to)

(oh, VB6/SP5/W2000)
Question by:tomrwilson
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 10

Accepted Solution

aeklund earned 400 total points
ID: 8241241
You can change your loop to a do..loop

do until rrTest.EOF
  if rsTest!id = 1 then exit do
LVL 70

Expert Comment

by:Éric Moreau
ID: 8241284
because it is an old syntax that can be replaced with :

do while rsTest.EOF = False
    if rsTest!id = 1 then exit do

Author Comment

ID: 8241634
Duh. :)  Thanks (to both).  Sorry to the other commenter, I picked the answer posted first.
LVL 10

Expert Comment

ID: 8241785
Glad to help...

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 12 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question