Search code examples
vbaformsloopsms-access

how to loop through selected list of forms in Ms Access


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.


Solution

  • 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.