I want to query 2 different recordsets for matching values and I don't know how to. I need to run down through one set of records and search the second set of records for matching values
This is what I have so far
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Const ForReading = 1
Const ForAppending = 1
Dim Stuff, myFSO, WriteStuff
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"SELECT AdsPath,samAccountName,Name,userPrincipalName,mailNickName,mail,givenName,sn FROM 'LDAP://Server1/dc=domain,dc=win' WHERE objectCategory='user'"
Set objConnection2 = CreateObject("ADODB.Connection")
Set objCommand2 = CreateObject("ADODB.Command")
objConnection2.Provider = "ADsDSOObject"
objConnection2.Open "Active Directory Provider"
Set objCommand2.ActiveConnection = objConnection
objCommand2.Properties("Page Size") = 1000
objCommand2.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand2.CommandText = _
"SELECT AdsPath,samAccountName,Name,userPrincipalName,mailNickName,mail,givenName,sn FROM 'LDAP://Server2/dc=Domain2,dc=win' WHERE objectCategory='user'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strUser = objRecordSet.Fields("Name").Value
strUser2 = objRecordSet2.Fields("Name").Value
If strUser = strUser2 Then
Set myFSO = CreateObject("Scripting.FileSystemObject")
Set WriteStuff = myFSO.OpenTextFile("Usermatch.csv", 8, True)
WriteStuff.WriteLine (strUser & "," & strUser2)
WriteStuff.Close
SET WriteStuff = NOTHING
SET myFSO = NOTHING
End If
objRecordSet.MoveNext
Loop
Any help would be cool
This is what I have so far
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Const ForReading = 1
Const ForAppending = 1
Dim Stuff, myFSO, WriteStuff
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"SELECT AdsPath,samAccountName,Name,userPrincipalName,mailNickName,mail,givenName,sn FROM 'LDAP://Server1/dc=domain,dc=win' WHERE objectCategory='user'"
Set objConnection2 = CreateObject("ADODB.Connection")
Set objCommand2 = CreateObject("ADODB.Command")
objConnection2.Provider = "ADsDSOObject"
objConnection2.Open "Active Directory Provider"
Set objCommand2.ActiveConnection = objConnection
objCommand2.Properties("Page Size") = 1000
objCommand2.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand2.CommandText = _
"SELECT AdsPath,samAccountName,Name,userPrincipalName,mailNickName,mail,givenName,sn FROM 'LDAP://Server2/dc=Domain2,dc=win' WHERE objectCategory='user'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strUser = objRecordSet.Fields("Name").Value
strUser2 = objRecordSet2.Fields("Name").Value
If strUser = strUser2 Then
Set myFSO = CreateObject("Scripting.FileSystemObject")
Set WriteStuff = myFSO.OpenTextFile("Usermatch.csv", 8, True)
WriteStuff.WriteLine (strUser & "," & strUser2)
WriteStuff.Close
SET WriteStuff = NOTHING
SET myFSO = NOTHING
End If
objRecordSet.MoveNext
Loop
Any help would be cool