Re: Getting list of users(mail,sn) from Active Directory using LDAP question



It looks like the first query finds an object with SN populated and the
second one doesn't. What are the DN's of the object returned? Are they the
same? Perhaps you are finding different objects with the two different
queries and only on of them has SN populated?

Note that SN isn't a mandatory attribute, so it can be null. As such, you
can't safely write code like:
result.Properties("sn")(0)

Unless you wrap that in this:
If result.Properties.Contains("SN") Then
....
End If

If you want to be sure that your results will all have SN and givenName, add
that to your filter:

(&.....(SN=*)(givenName=*))

Joe K.

"Patrick.O.Ige" <naijacoder@xxxxxxxxxxx> wrote in message
news:%23mwfy6ZIGHA.1424@xxxxxxxxxxxxxxxxxxxxxxx
> Yes i did Joe and thx for the reply
> I added 4 properties to Load you can see it in my code below
> But i get it to working only if i filter using:-
> Mysearcher.Filter = "(&(anr=username)(objectCategory=person))"
> but with
> Mysearcher.Filter = "(&(objectClass=user)(objectCategory=user))"
> i don't get any result using
> "result.Properties("sn")(0)"
> Is my filter wrong!!!
> Are you getting me?
> Patrick
>
>
>
> "Joe Kaplan (MVP - ADSI)" <joseph.e.kaplan@xxxxxxxxxxxxxxxxxxxxxxxx> wrote
> in message news:OOJZKbQIGHA.208@xxxxxxxxxxxxxxxxxxxxxxx
>> Did you add SN and givenName to the PropertiesToLoad on the
>> DirectorySearcher?
>>
>> You are correct that you really don't want to call GetDirectoryEntry for
>> a
>> simple property reader. That should only be done if you need to modify
> the
>> object.
>>
>> Joe K.
>>
>> "Patrick.O.Ige" <naijacoder@xxxxxxxxxxx> wrote in message
>> news:OUQw54KIGHA.2680@xxxxxxxxxxxxxxxxxxxxxxx
>> > The code below works fine but if i use
>> > Response.Write("First Name=" + result.Properties("givenname")(0) +
>> > "<br>Last
>> > Name=" + result.Properties("sn")(0) + "")
>> > To display the results it doesn't work unless i do
>> > "result.GetDirectoryEntry.Properties("sn").Value"
>> > to get a value and using GetDirectoryEntry makes the query very slow.
>> >
>> > But if i filter by using :-
>> > Mysearcher.Filter = "(&(anr=username)(objectCategory=person))"
>> > I can retrieve result by doing :
>> > Response.Write("First Name=" + result.Properties("givenname")(0) +
>> > "<br>Last
>> > Name=" + result.Properties("sn")(0) + "")
>> >
>> > What am i doing wrong?
>> > Any advice?
>> >
>> >
>> >
>> > Dim Mysearcher As New DirectorySearcher(rootEntry)
>> >
>> > 'Mysearcher.Filter = "(&(anr=username)(objectCategory=person))"
>> >
>> > Mysearcher.Filter = "(&(objectClass=user)(objectCategory=user))"
>> >
>> > Mysearcher.PropertiesToLoad.Add("samaccountname")
>> >
>> > Mysearcher.PropertiesToLoad.Add("givenname")
>> >
>> > Mysearcher.PropertiesToLoad.Add("sn")
>> >
>> > Mysearcher.PropertiesToLoad.Add("mail")
>> >
>> >
>> >
>> > Dim Myresults As SearchResultCollection
>> >
>> > Myresults = Mysearcher.FindAll()
>> >
>> > Dim result As SearchResult
>> >
>> > For Each result In Myresults
>> >
>> > Response.Write("" &
>> > result.GetDirectoryEntry().Properties("samaccountname").Value & "<br>")
>> >
>> > 'Response.Write("First Name=" + result.Properties("givenname")(0) +
>> > "<br>Last Name=" + result.Properties("sn")(0) + "")
>> >
>> > 'Response.Write("" & result.Properties("sn")(0) & "")
>> >
>> > 'Response.Write("<br>Email=" + result.Properties("mail")(0) + "<br>")
>> >
>> > Response.Write("" + result.GetDirectoryEntry.Properties("sn").Value +
>> > "<br>")
>> >
>> > Next
>> >
>> >
>> >
>> >
>>
>>
>
>


.



Relevant Pages

  • Problem with filling in Bookmarks in Word
    ... you can still see my first query. ... Sub ReportToWord ... Dim objWord As Object ... Set objWord = CreateObject ...
    (comp.databases.ms-access)
  • Re: HELP PLEASE
    ... Then the only thing I can see wrong is the missing brackets ... >>Check the first query in your posted code more ... >>Are you sure that the CaseID field is a numeric type? ... Dim dbs As DAO.Database ...
    (microsoft.public.access.modulesdaovba)
  • Re: sorting
    ... Why are you changing the Row Source of the same combobox twice? ... Steve Schapel, Microsoft Access MVP ... > But I need to alter the first query before I can call the second ... > do I need to use a third combo box just to send the filter to the first ...
    (microsoft.public.access.forms)
  • Re: HELP PLEASE
    ... Check the first query in your posted code more carefully. ... >>> Dim dbs As DAO.Database ... >>> Dim varNoteBatch As Variant ...
    (microsoft.public.access.modulesdaovba)
  • RE: Data Retrieval Speed
    ... within the character string of the field, ... the first query all of the following searches execute very quickly, ... >> the forms on about six other PCs on the network. ... >> dim MyRecordset as recordset ...
    (microsoft.public.access.queries)