Can't Exit Loop 
Author Message
 Can't Exit Loop

I'm unable to get Access 2000 to exit the following loop:

Private Sub cmdTest_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim findstr As String
Dim strSomething As String
Set db = CurrentDb
Set rst = db.OpenRecordset("tblAnything", dbOpenDynaset)
findstr = "fldSomething = 'Black&Blue'"
rst.MoveFirst
    Do Until rst.EOF = True
       With rst
          .FindNext findstr
          .Edit
          strSomething = rst!fldSomething
          .Update
          If .EOF = True Then GoTo Label
      End With
  Loop
Label:
Exit Sub

Can you spot the problem?

Rick Mitchell
Springville, CA



Wed, 27 Oct 2004 11:51:11 GMT  
 Can't Exit Loop
If FindNext fails, I believe it stays on the same record.
If it succeeds, of course, you're on a record and not at EOF.

You might want to use a test for rst.NoMatch instead of EOF.

HTH
    - Turtle

Quote:

> I'm unable to get Access 2000 to exit the following loop:

> Private Sub cmdTest_Click()
> Dim db As DAO.Database
> Dim rst As DAO.Recordset
> Dim findstr As String
> Dim strSomething As String
> Set db = CurrentDb
> Set rst = db.OpenRecordset("tblAnything", dbOpenDynaset)
> findstr = "fldSomething = 'Black&Blue'"
> rst.MoveFirst
>     Do Until rst.EOF = True
>        With rst
>           .FindNext findstr
>           .Edit
>           strSomething = rst!fldSomething
>           .Update
>           If .EOF = True Then GoTo Label
>       End With
>   Loop
> Label:
> Exit Sub

> Can you spot the problem?

> Rick Mitchell
> Springville, CA



Wed, 27 Oct 2004 11:56:13 GMT  
 Can't Exit Loop
You're exactly right.  Problem solved.  Thanks!
Quote:

> If FindNext fails, I believe it stays on the same record.
> If it succeeds, of course, you're on a record and not at EOF.

> You might want to use a test for rst.NoMatch instead of EOF.

> HTH
>     - Turtle


> > I'm unable to get Access 2000 to exit the following loop:

> > Private Sub cmdTest_Click()
> > Dim db As DAO.Database
> > Dim rst As DAO.Recordset
> > Dim findstr As String
> > Dim strSomething As String
> > Set db = CurrentDb
> > Set rst = db.OpenRecordset("tblAnything", dbOpenDynaset)
> > findstr = "fldSomething = 'Black&Blue'"
> > rst.MoveFirst
> >     Do Until rst.EOF = True
> >        With rst
> >           .FindNext findstr
> >           .Edit
> >           strSomething = rst!fldSomething
> >           .Update
> >           If .EOF = True Then GoTo Label
> >       End With
> >   Loop
> > Label:
> > Exit Sub

> > Can you spot the problem?

> > Rick Mitchell
> > Springville, CA



Thu, 28 Oct 2004 21:09:06 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Can't exit loop

2. Open a recordset when a loop exit's

3. Can't see images in Publisher, cans see thumbs in image manager

4. Exit Application button closes DB but doesn't exit Access

5. looping slides with combining other slides/presentations that aren't looped

6. Exiting while loops

7. Loop Exit after Last Find

8. Exit Loop on keypress?

9. Graceful exit from SolverSolve Solver loop found

10. how to exit loop?


 
Powered by phpBB® Forum Software © phpBB Group