I am trying to loop through a selected list of forms in Ms Access. Like we can do it with sheets in Excel in this way
For Each shtSheet In ThisWorkbook.Worksheets(Array("Sheet2", "Sheet1"))
Is there a way to do some similar thing in Access for forms?
Thanks in advance.
CodePudding user response:
For example
Dim f As Form
Dim arr
arr = Array("Form1", "Form2")
Dim element
For Each element In arr
Set f = Forms(element)
Next
But set f= Forms(element)
will fail if the form is not loaded.
CodePudding user response:
You can list them as objects:
Public Function ListSomeForms()
Dim Form As Object
Dim FormNames As Variant
Dim Item As Variant
FormNames = Array("FormName1", "FormName2")
For Each Item In FormNames
Set Form = CurrentProject.AllForms(Item)
Debug.Print Form.Name, Form.IsLoaded
Next
Set Form = Nothing
End Function