VBScript: how to set values from recordset to string
Posted
by phill
on Stack Overflow
See other posts from Stack Overflow
or by phill
Published on 2008-11-19T23:08:39Z
Indexed on
2010/06/11
19:02 UTC
Read the original article
Hit count: 225
This is probably a beginner question, but how do you set a recordset to a string variable?
Here is my code:
Function getOffice (strname, uname)
strEmail = uname
WScript.Echo "email: " & strEmail
Dim objRoot : Set objRoot = GetObject("LDAP://RootDSE")
Dim objDomain : Set objDomain = GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))
Dim cn : Set cn = CreateObject("ADODB.Connection")
Dim cmd : Set cmd = CreateObject("ADODB.Command")
cn.Provider = "ADsDSOObject"
cn.Open "Active Directory Provider"
Set cmd.ActiveConnection = cn
cmd.CommandText = "SELECT physicalDeliveryOfficeName FROM '" & objDomain.ADsPath & "' WHERE mail='" & strEmail & "'"
cmd.Properties("Page Size") = 1
cmd.Properties("Timeout") = 300
cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Dim objRS : Set objRS = cmd.Execute
WScript.Echo objRS.Fields(0)
Set cmd = Nothing
Set cn = Nothing
Set objDomain = Nothing
Set objRoot = Nothing
Dim arStore
Set getOffice = objRS.Fields(0)
Set objRS = Nothing
End function
When I try to run the function, it throws an error "vbscript runtime error: Type mismatch" I presume this means it can't set the string variable with a recordset value.
How do I fix this problem?
© Stack Overflow or respective owner