shabbaranks
Registered User.
- Local time
- Today, 13:45
- Joined
- Oct 17, 2011
- Messages
- 300
Hi,
This code was copied from another location (not this forum) and before I just copied and pasted it I wanted to understand what exactly it was doing and how to trigger it correctly.
What Im trying to do firstly is learn how to trigger this when the DB is open and secondly I then want to populate a table with AD users from a specific group.
Thanks
This code was copied from another location (not this forum) and before I just copied and pasted it I wanted to understand what exactly it was doing and how to trigger it correctly.
Code:
Private Sub Form_load()
Public Sub TestCode(strDomain As String, strGroup As String)
Dim objGroup As Object
Dim objRootDSE As Object
Dim objNet As Object
Dim strDomain As Variant
Dim objUser As Object
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strGroup As String
Dim i As Integer
Set db = CurrentDb
'Get one record just so we have a record set to add to.
strSQL = "SELECT TOP 1 * FROM ADUsers"
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
Set objNet = CreateObject("WScript.Network")
Set objRootDSE = GetObject("[URL]ldap://rootDSE[/URL]")
Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
For Each objUser In objGroup.Members
i = i + 1
With rs
.AddNew
!UserName = objUser.Name
.Update
End With
Next
Set rs = Nothing
Set db = Nothing
Set objGroup = Nothing
Set objRootDSE = Nothing
Set objNet = Nothing
End Sub
End Sub
What Im trying to do firstly is learn how to trigger this when the DB is open and secondly I then want to populate a table with AD users from a specific group.
Thanks