| ش | ی | د | س | چ | پ | ج |
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
|
For Each Ctl In Me.Controls
If Ctl.ControlType=(acTextBox Or acComboBox) Then
'DO SomeThing
Next
'If Ctl.ControlType=acTextBox Or Ctl.ControlType=acComboBox
لوپ در کنترلهای یک سابفرم :
در خط اول در کنترل های فرم می گردد چنانچه TypeName آن SubForm بود میرود به Form آن و تمام کنترل ها را در پنجره immidiate window محیط Vba نمایش میدهد ( Ctrl+G)
For Each ctl In frm.Controls
If TypeName(ctl) = "SubForm" Then
Debug.Print ctl.Name & " is a SubForm"
For Each ctlSub in ctl.Form.Controls
Debug.Print ctlSub.Name
Next
End If
Nextحال در جواب سوال بعد از ایجاد لوپ
Ctl.BackColor = IIf(Ctl.Name = Screen.ActiveControl.Name, 8454143, 16777215)
البته در کنترل تب ، تب هایی وجود دارد و هر تب فقط یک پیج دارد رفرنس به تب خاص و پیج حاوی کنترل ها ( فرضا نام تب کنترل TabCtl0 باشد.)
iTabPage=0 پیج ایندکس تب اول صفر است
For Each Ctl In TabCtl0.Pages(iTabPage).Controls
'iTabPage=iif(iTabPage>15,0,iTabPage=iTabPage+1)
For i=0 To TabCtl0.Pages.Count -1 لوپ در پیج ها
ControlType Property :
| acBoundObjectFrame | Bound object frame |
| acCheckBox | Check box |
| acComboBox | Combo box |
| acCommandButton | Command button |
| acCustomControl | ActiveX (custom) control |
| acImage | Image |
| acLabel | Label |
| acLine | Line |
| acListBox | List box |
| acObjectFrame | Unbound object frame or chart |
| acOptionButton | Option button |
| acOptionGroup | Option group |
| acPage | Page |
| acPageBreak | Page break |
| acRectangle | Rectangle |
| acSubform | Subform/subreport |
| acTabCtl | Tab |
| acTextBox | Text box |
| acToggleButton | Toggle button |
TypeName(Ctl)
Ctl.ControlType
If TypeOf Ctl is .....