Results 1 to 10 of 10
  1. #1
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162

    Question Active Directory

    Reference https://www.accessforums.net/program...tml#post276477 - how does this work exactly? By that I understand the code and what its doing but how would I output this record set to a table for example?



    Thanks
    Last edited by June7; 05-20-2015 at 09:05 AM. Reason: split thread

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    This code shows an iteration of the recordset.
    http://www.dbforums.com/showthread.p...34#post6334634

  3. #3
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    Thanks so say I have my module which is recording the recordset (I think I'm using this terminology correctly) how would I call this on say a form_load()?

    Thanks

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by shabbaranks View Post
    Thanks so say I have my module which is recording the recordset (I think I'm using this terminology correctly) how would I call this on say a form_load()?

    Thanks
    I am not sure what, exactly, you are calling. But, you can call a function that is in a General Module by using the functions name. If you want to call a function when a form is opened, you could use the form's On Load event. The syntax would be like this.
    Call FunctionName()

    Post #3 has a function named UserRecordset. Calling that function would be Call UserRecordset(). Although, I do not believe the code in post #3 is what you are looking for.

  5. #5
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    Thank you again, I am slowly understanding whats going on here - but I feel my code my be a little off. What I intend on doing is querying LDAP\Active Directory on load with a list of users who are a member of a group. Im yet to get the group part working but am slowly getting to terms with an ldap query - I think....

    Is this on the right path?

    Code:
    Private Function queryAD()
    Dim rs As Object
    Dim uName As String
    Dim extensions() As Variant
    Dim i As Integer
    Public Const adOpenStatic     As Integer = 3
    Public Const adLockReadOnly   As Integer = 1
    Public Const adCmdUnspecified As Integer = -1
        'Instantiate recordset
        Set rs = CreateObject("ADODB.Recordset")
        
        'Open LDAP recordset
        strSQL = "INSERT INTO Lb_UserNames_tbl" & _
                 "SELECT cn, givenName, sn," & _
                 "FROM 'LDAP://DC=domain,DC=local'" & _
                 "WHERE objectClass='user' AND objectCategory='Person'"
        
                End If
            
        End If
        
        'Close connection and tidy up
        rs.Close
        Set rs = Nothing
        
    End Function

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by shabbaranks View Post
    ...Is this on the right path?...
    This is the instantiation of an Object.
    Set rs = CreateObject("ADODB.Recordset")


    EDIT: You never attempt to access the object. Then, you create a literal string. The code does not seem to do anything.

    Perhaps you should start over and explain what your objective(s) is. You mentioned retrieving data but then you create an INSERT INTO statement. It is not clear what your objective is.

  7. #7
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    Ok what I am trying to do is query LDAP\Active directory and retrieve the CN, given name and surname of users who are a member of a particular AD group and then insert them into a table called Lb_UserNames_tbl this trigger will occur on a form_load()

    I hope this makes more sense

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I took a closer look at the code I linked to and I take back the comment I made about the rs object not being initialized. It is initialized using late binding. You just need to use the SQL provided in the example to retrieve the dataset.

    So include everything, up to an including
    'Iterate through recordset
    If Not rs.EOF And Not rs.BOF Then

    From there you can include an INSERT INTO

    Then

    End If

    'Close connection and tidy up
    rs.Close
    Set rs = Nothing


    What this should do is write the first record. I can't remember if ADO will go to the first record automatically. With DAO I would use rs.Movefirst. Actually, before using any SQL, I would test what my ADO connection was getting by placing something in there like this.

    'If userPrincipalName is null, then uName = "@"
    Debug.Print Nz(rs.fields("userPrincipalName"), "@")

  9. #9
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    Thanks am I correct in thinking I wouldn't need to re run the strSQL string and that I would use the results from that query to insert into the table? Sorry this aspect of Access is new to me - thank you.

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by shabbaranks View Post
    Thanks am I correct in thinking I wouldn't need to re run the strSQL string and that I would use the results from that query to insert into the table? Sorry this aspect of Access is new to me - thank you.
    I am not sure what you mean be re-run. The ADO connection gives you access to the AD. This is represented by the object, rs. The sample code has a string that is defined as

    Code:
        'Open LDAP recordset
        strSQL = "SELECT userPrincipalName, sAMAccountName, mail, telephoneNumber, otherTelephone " & _
                 "FROM 'LDAP://DC=xxxxxx,DC=pri'" & _
                 "WHERE objectClass='user' AND objectCategory='Person'"
    This strSQL is used once to retrieve a data set. The query is implemented here.
    rs.Open strSQL, "Provider=ADSDSOObject;", adOpenStatic, adLockReadOnly, adCmdUnspecified

    With that, you can debug.print a field from one of the recordsets to test that your code is working, thus far.
    'If userPrincipalName is null, then uName = "@"
    Debug.Print Nz(rs.fields("userPrincipalName"), "@")

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access and Active Directory...
    By Voodeux2014 in forum Access
    Replies: 4
    Last Post: 01-19-2015, 02:31 PM
  2. Replies: 1
    Last Post: 01-11-2014, 12:39 PM
  3. MS Active Directory
    By pkelly in forum Access
    Replies: 9
    Last Post: 10-21-2011, 08:26 AM
  4. access+Active directory
    By cpcp in forum Access
    Replies: 6
    Last Post: 11-15-2010, 02:30 AM
  5. Active Directory coding
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-28-2010, 08:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums