How to use Controls collection in Access 2003 and VBA

后端 未结 4 498
遥遥无期
遥遥无期 2020-12-18 15:59

I\'m having a heck of the time trying to figure this one out.

I want to pass a Controls collection to a function but I get a type mismatch. Here\'s the function decl

4条回答
  •  难免孤独
    2020-12-18 16:22

    It does seem odd that you can't pass the Page's control collection directly. It might have something to do with the fact that the Pages collection itself is a special type of control collection.

    Another alternative would be to declare the "topCtlList" parameter as Object instead of controls. It makes the code less readable and potentially more error prone, but it should remove the type-mismatch error.

    Public Function DoStuffToCollection(topCtlList As Object, isLocked As Boolean)
    'Debug.Print TypeName(topCtlList)
    Dim ctl As Control
    For Each ctl In topCtlList
       Debug.Print ctl.Name
    Next ctl
    
    End Function
    

提交回复
热议问题