Early Exit from a Loop : For Each « Language Basics « VBA / Excel / Access / Word

Early Exit from a Loop

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 
End Sub 


Related examples in the same category

1.Using the For Each...Next Loop
2.Using Nested Loops
3.Loop through ranges
4.For...Each Variation
5.Looping through the elements in an array