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
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
This code shows an iteration of the recordset.
http://www.dbforums.com/showthread.p...34#post6334634
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.
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
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.
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![]()
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"), "@")
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
This strSQL is used once to retrieve a data set. The query is implemented here.Code:'Open LDAP recordset strSQL = "SELECT userPrincipalName, sAMAccountName, mail, telephoneNumber, otherTelephone " & _ "FROM 'LDAP://DC=xxxxxx,DC=pri'" & _ "WHERE objectClass='user' AND objectCategory='Person'"
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"), "@")