Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Active Directory Sync in Access 1

Status
Not open for further replies.

migv1

Technical User
Apr 23, 2004
39
0
0
US
I'm trying to create an Active Directory Synchronization function in Access, similar to that found in Project Server 2007. I can enumerate all the members of my AD group with the following code:

Sub ADMembers()
Dim strSql As String
Dim LoginName As Object, tblEmployees As Table
Dim adsGroup As IADsGroup, adsMembers As IADsMembers
Dim varItem As Object
Set adsGroup = GetObject("WinNT://MYDOMAIN/MYADGROUP")
Set adsMembers = adsGroup.Members
For Each varItem In adsMembers
Debug.Print varItem.Name
Next varItem
End Sub

What I need to do next is to compare each varItem.Name to the values in the LoginName field in tblEmployees. If there is a match, do nothing (the employee is already in the table). If there is no match, create a new record in tblEmployees with the value of varItem.Name inserted into the LoginName field.

What is the best way to accomplish this task? (Sorry if this question has been asked and answered before, but I did a few searches and didn't find what I needed.)
 
You may try this:
Code:
Sub ADMembers()
    Dim adsGroup As IADsGroup, adsMembers As IADsMembers
    Dim varItem As Object
    Set adsGroup = GetObject("WinNT://MYDOMAIN/MYADGROUP")
    Set adsMembers = adsGroup.Members
    For Each varItem In adsMembers
      If IsNull(DLookup("LoginName", "tblEmployees", "LoginName='" & varItem.Name & "'")) Then
        CurrentDb.Execute "INSERT INTO tblEmployees (LoginName) VALUES ('" & varItem.Name & "')"
      End If
      Debug.Print varItem.Name
    Next varItem
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top