Re: Trouble With "For Each" and "Next"

Giganews Newsgroups
Subject: Re: Trouble With "For Each" and "Next"
Posted by:  Thelma Lubkin (thel…
Date: 29 Aug 2006

Dale <mtec…> wrote:
: Access 2000

: The below code works Except it will not stop looping when a control is
: null. It will display the msgBox and then continue to the next control.

: Dim ctl As Control

: For Each ctl in Me,Controls
:  If ctl.Tag = "1" And IsNull(ctl) Then
:      MsgBox("Required Field Is Blank")
:      ctl.SetFocus
:      DoCmd.CancelEvent
      Exit For            <================
:  End If
: Next ctl

    You need to exit the loop: see above.
: Dale



In response to

Trouble With "For Each" and "Next" posted by Dale on 28 Aug 2006