VBA/Excel/Access/Word/Access/DBEngine

Материал из VB Эксперт

Перейти к: навигация, поиск

Enumerate groups and users

 
Sub EnumGroupsAndUsers()
    Dim grp As Group
    Dim usr As User
    For Each usr In DBEngine(0).Users
        Debug.Print usr.Name
        For Each grp In usr.Groups
            Debug.Print vbTab; grp.Name
        Next
    Next
End Sub



Reference TableDefs from DBEngine

 
Sub temp()
    Dim db As Database
    Set db = DBEngine(0)(0)
    Debug.Print "Table count: " & db.TableDefs.Count
End Sub



Save table to a collection

 
Sub exaCollections()
    Dim colParent As New Collection
    Dim colChild As New Collection
 
    Dim tdfBooks As TableDef
    Dim objVar As Object
 
    Set tdfBooks = DBEngine(0)(0).TableDefs!Employees
 
    colParent.Add colChild
    colParent.Add tdfBooks
 
    Debug.Print colParent.Count
    For Each objVar In colParent
       If TypeOf objVar Is Collection Then
          Debug.Print "Collection"
       ElseIf TypeOf objVar Is TableDef Then
          Debug.Print objVar.Name
       End If
    Next
 
End Sub