HandsOn Early Exit from a Loop

1. In the Code window, enter the GetControls2 procedure as shown below.

Sub GetControls2()

Dim myControl As Control Dim myForm As Form

DoCmd.OpenForm "Customers" Set myForm = Screen.ActiveForm

For Each myControl In myForm Debug.Print myControl.Name If myControl.Name = "Address" Then Exit For

Next End Sub

The GetControls2 procedure examines the names of the controls in the currently open Customers form. If Visual Basic encounters the control named "Address," it exits the loop.

0 0

Post a comment