VBA/Excel/Access/Word/Access/DBEngine

Материал из VB Эксперт
Перейти к: навигация, поиск

Enumerate groups and users

   <source lang="vb">

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

</source>
   
  


Reference TableDefs from DBEngine

   <source lang="vb">

Sub temp()

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

End Sub

</source>
   
  


Save table to a collection

   <source lang="vb">

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

</source>