HandsOn Using the For Next Loop

1. Import the Customers table and Customers form from the Acc2003_ Chap01.mdb database file that you worked with in Chapter 1. To do this, choose File | Get External Data | Import. Specify the database name as Acc2003_Chap01 and click Import. In the Import Objects dialog box, select the Customers table and Customers form and click OK.

2. Now, open the Customers form in Form view.

3. Switch to the Visual Basic Editor window and insert a new module.

4. In the module's Code window, enter the GetTextBoxNames procedure as shown below.

Sub GetTextBoxNames() Dim myForm As Form Dim myControl As Control Dim c As Integer

Set myForm = Screen.ActiveForm Set myControl = Screen.ActiveControl

If TypeOf myForm(c) Is TextBox Then

MsgBox myForm(c).Name End If Next c End Sub

The conditional statement (If.. .Then) nested inside the For.. .Next loop tells Visual Basic to display the name of the active control only if it is a text box.

Part I

0 0

Post a comment