I use AD Explorer to add values to the roomNumber attribute of users. When I
read these later using VBScript, I get Type Mismatch errors whenever there is
a value present... it's a Unicode string, yet it doesn't act like a string!
Always errors out when I attempt to read it.

Example:

Dim objComm, objRecordSet, strDNSDomain, objConn
Dim strQuery, strFilter
set objComm = CreateObject("ADODB.Connection")
objComm.Provider = "ADsDSOObject"
objComm.Open "Active Directory Provider"
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
set objConn = CreateObject("ADODB.Command")
objConn.ActiveConnection = objComm
objConn.Properties("Page Size") = 10
strFilter = "(&(objectClass=person)(objectClass=user)(objectCategory=Person))"
objConn.CommandText = "<LDAP://DC=corp,DC=mydomain,DC=net>;" & strFilter &
";cn,sAMAccountName,roomNumber,distinguishedName;subtree"
Set objRecordset = objConn.Execute(strQuery)
objRecordset.MoveFirst
While Not objRecordSet.EOF

WScript.Echo objRecordSet.Fields("roomNumber")

objRecordSet.MoveNext
Wend

Re: roomNumber attribute - Type Mismatch? by Richard

Richard
Fri Jul 11 13:06:59 PDT 2008


"Mark Z." <MarkZ@discussions.microsoft.com> wrote in message
news:A61E7CA4-5539-4F4C-AFF3-B762FBD97640@microsoft.com...
>I use AD Explorer to add values to the roomNumber attribute of users. When
>I
> read these later using VBScript, I get Type Mismatch errors whenever there
> is
> a value present... it's a Unicode string, yet it doesn't act like a
> string!
> Always errors out when I attempt to read it.
>
> Example:
>
> Dim objComm, objRecordSet, strDNSDomain, objConn
> Dim strQuery, strFilter
> set objComm = CreateObject("ADODB.Connection")
> objComm.Provider = "ADsDSOObject"
> objComm.Open "Active Directory Provider"
> Set objRootDSE = GetObject("LDAP://RootDSE")
> strDNSDomain = objRootDSE.Get("defaultNamingContext")
> set objConn = CreateObject("ADODB.Command")
> objConn.ActiveConnection = objComm
> objConn.Properties("Page Size") = 10
> strFilter =
> "(&(objectClass=person)(objectClass=user)(objectCategory=Person))"
> objConn.CommandText = "<LDAP://DC=corp,DC=mydomain,DC=net>;" & strFilter
> &
> ";cn,sAMAccountName,roomNumber,distinguishedName;subtree"
> Set objRecordset = objConn.Execute(strQuery)
> objRecordset.MoveFirst
> While Not objRecordSet.EOF
>
> WScript.Echo objRecordSet.Fields("roomNumber")
>
> objRecordSet.MoveNext
> Wend

The roomNumber attribute is multi-valued. Your code must allow for the
possibility that there are no values. For example, you might use code
similar to:
==========
Do Until objRecordset.EOF
arrRmNums = objRecordset.Fields("roomNumber").Value
If IsNull(arrRmNums) Then
strRoom = ""
Else
strRoom = ""
For Each strItem In arrRmNums
If (strRoom = "") Then
strRoom = strItem
Else
strRoom = strRoom & "," & strItem
End If
Next
End If
Wscript.Echo strRoom
objRecordset.MoveNext
Loop

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--