ش | ی | د | س | چ | پ | ج |
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 |
Sub forEachExit()Dim element As VariantDim animals(0 To 5) As String'We have created an array that can hold 6 elementsanimals(0) = "Dog"animals(1) = "Cat"animals(4) = "Snake"animals(2) = "Bird"animals(3) = "Buffalo"'Here we fill each element of the arrayanimals(5) = "Duck-billed Platypus"For Each element In animals'print each element to the immediate window'iterates over the animals collectionDebug.Print elementEnd SubIf element = "Buffalo" Then Exit For'if, at any point, the element becomes equalNext
The output to the immediate window will be (we exited the loop before all items could be printed):
Dog Cat Bird Buffalo |
Dim MyArray() As String
ReDim Preserve MyArray(2)
Public Function HadleOpenForms()
Dim arr() As String
Redim Preserve arr(Forms.Count)
If forms.Count Then
For i=0 To Forms.Count-1
' quotation-marks-in-string-expressions
Arr(i)="" & Forms(i).Name & ""
x=x & iif(x="",",","") & Arr(i)
Next
Debug.Print x
Else
Exit Function
End If
End Function
تابع بالا را تست کنید چنانچه باید اصلاح شود در نظرات این یادداشت قید کنید و اگر درست است زمانیکه فرم هایتان بصورت Tabbed Document باز است اجرا و نتیجه را در نظرات کپی کنید ( در پنجره immidate window محیط vba اکسس اگر تابع درست عمل کند و خطا ندهد ، چاپ میشود)
dim intx as integerdim intCount as integerintCount = Forms.count-1for intX= intCount to 0 step -1docmd.close acform,forms(intX).namenext
Arr=Array("...","....","....")
CountOpenFrms = Application.Forms.Count
SysCmd شامل Action و دوتا آرگومان است کد زیر
مقدار عددی را برمی گرداند که مشخص میکند Object
باز است یا بسته و یا .....
ObjState = SysCmd(acSysCmdGetObjectState, _
Application.CurrentObjectType, _
Application.CurrentObjectName)
vba/api/access.acsyscmdaction