You've already found a valid solution, but I want to explain what's going on here.
The keys of a Dictionary
object can be of any type except arrays (see the docs). Since you used the Set
statement, the variable uacResult
is an object reference (more on that later). When you call the Item
method on the Dictionary
, it is actually looking for key that matches the object reference, instead of searching for the string as you expected. CStr()
corrects that by explicitly converting the object reference to a string.
Since you used the Set
keyword in its assignment, uacResult
ends up containing a reference to a Field
object, since the default property of the Recordset
object is the Fields
collection. When you call CStr(uacResult)
, this is converting the object to a string by calling the default property of the Field
object, which is the Value
property. You could achieve the same effect in a few different ways:
' method 1 - from accepted answer (https://stackoverflow.com/a/17786308/249624)
set uacResult = objRS("userAccountControl")
Response.Write uac.Item(CStr(uacResult))
' method 2 - explicitly using the Value property
set uacResult = objRS("userAccountControl")
Response.Write uac.Item(uacResult.Value)
' method 3 - make uacResult a string instead of a Field object
uacResult = objRS("userAccountControl")
Response.Write uac.Item(uacResult)
' method 4 - same as method 3, but explicitly use the Value property
uacResult = objRS("userAccountControl").Value
Response.Write uac.Item(uacResult)