N
nYssa
Hello,
I have a custom outlook form for annual leave and I am trying to auto
populate the department field for the current outlook user based on the
department field stored in active directory. I am using outlook 2003 and not
having much luck.
I have tried the following code in the Item_Open function of my form and am
getting no records in my recordset.
GALQueryFilter = "(& (mailnickname=*) (|
(&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=contact))(objectCategory=group)(objectCategory=publicFolder) ))"
strQuery = "<LDAP://" & DomainName & "/" & strDefaultNamingContext & ">;" &
GALQueryFilter & ";GivenName,sn,department;subtree"
Set oConn = CreateObject("ADODB.Connection")
Set oComm = CreateObject("ADODB.Command")
Set rs = CreateObject("ADODB.Recordset")
oConn.Provider = "ADsDSOOBJECT" ' ADSI OLE-DB provider
oConn.Open "ADs Provider"
oComm.ActiveConnection = oConn
oComm.Properties("Page Size") = 1000
oComm.CommandText = strQuery
'HAVE TRIED THIS WITH NO DIFFERENCE EITHER
'oComm.CommandText = "select GivenName,sn,department from 'LDAP://perss2'"
rs = oComm.Execute
item.userproperties("bDivisionName") = rs.Fields("department")
oConn.Close
set oConn = nothing
set oComm = nothing
set rs = nothing
HAVE ALSO TRIED THIS CODE with the same result, no records:
' Determine the DNS domain from the RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
' Create and open an ADO connection to AD
Set objConnectionAD = CreateObject("ADODB.Connection")
Set objCommandAD = CreateObject("ADODB.Command")
Set objRecordSetAD = CreateObject("ADODB.Recordset")
objConnectionAD.Provider = "ADsDSOObject"
objConnectionAD.Open "Active Directory Provider"
' Set connection properties
With objCommandAD
.ActiveConnection = objConnectionAD
.CommandText = _
"Select userAccountControl, distinguishedName," & _
" sAMAccountname, department, displayName" & _
" FROM 'LDAP://" & strDNSDomain & "'" & _
" WHERE objectCategory = 'person' AND" & _
" objectClass = 'user' "
.Properties("Page Size") = 1000
.Properties("Timeout") = 30
.Properties("Searchscope") = ADS_SCOPE_SUBTREE
.Properties("Cache Results") = False
End With
Set objRecordSetAD = objCommandAD.Execute
' Move to the first record in the recordset
objRecordSetAD.MoveFirst
while not objRecordSetAD.EOF
mystring = mystring & " " & objRecordSetAD.Fields("department").Value
item.userproperties("bDivisionName") =
objRecordSetAD.Fields("department").Value
objRecordSetAD.MoveNext
wend
item.userproperties("bDivisionName") = mystring
'END CODE
Can someone please help. Thanks, nYssa
I have a custom outlook form for annual leave and I am trying to auto
populate the department field for the current outlook user based on the
department field stored in active directory. I am using outlook 2003 and not
having much luck.
I have tried the following code in the Item_Open function of my form and am
getting no records in my recordset.
GALQueryFilter = "(& (mailnickname=*) (|
(&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=contact))(objectCategory=group)(objectCategory=publicFolder) ))"
strQuery = "<LDAP://" & DomainName & "/" & strDefaultNamingContext & ">;" &
GALQueryFilter & ";GivenName,sn,department;subtree"
Set oConn = CreateObject("ADODB.Connection")
Set oComm = CreateObject("ADODB.Command")
Set rs = CreateObject("ADODB.Recordset")
oConn.Provider = "ADsDSOOBJECT" ' ADSI OLE-DB provider
oConn.Open "ADs Provider"
oComm.ActiveConnection = oConn
oComm.Properties("Page Size") = 1000
oComm.CommandText = strQuery
'HAVE TRIED THIS WITH NO DIFFERENCE EITHER
'oComm.CommandText = "select GivenName,sn,department from 'LDAP://perss2'"
rs = oComm.Execute
item.userproperties("bDivisionName") = rs.Fields("department")
oConn.Close
set oConn = nothing
set oComm = nothing
set rs = nothing
HAVE ALSO TRIED THIS CODE with the same result, no records:
' Determine the DNS domain from the RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
' Create and open an ADO connection to AD
Set objConnectionAD = CreateObject("ADODB.Connection")
Set objCommandAD = CreateObject("ADODB.Command")
Set objRecordSetAD = CreateObject("ADODB.Recordset")
objConnectionAD.Provider = "ADsDSOObject"
objConnectionAD.Open "Active Directory Provider"
' Set connection properties
With objCommandAD
.ActiveConnection = objConnectionAD
.CommandText = _
"Select userAccountControl, distinguishedName," & _
" sAMAccountname, department, displayName" & _
" FROM 'LDAP://" & strDNSDomain & "'" & _
" WHERE objectCategory = 'person' AND" & _
" objectClass = 'user' "
.Properties("Page Size") = 1000
.Properties("Timeout") = 30
.Properties("Searchscope") = ADS_SCOPE_SUBTREE
.Properties("Cache Results") = False
End With
Set objRecordSetAD = objCommandAD.Execute
' Move to the first record in the recordset
objRecordSetAD.MoveFirst
while not objRecordSetAD.EOF
mystring = mystring & " " & objRecordSetAD.Fields("department").Value
item.userproperties("bDivisionName") =
objRecordSetAD.Fields("department").Value
objRecordSetAD.MoveNext
wend
item.userproperties("bDivisionName") = mystring
'END CODE
Can someone please help. Thanks, nYssa