Click to See Complete Forum and Search --> : VBScript: Object Required '[string: ...]' error


gpm1982
11-18-2007, 10:02 PM
Hi everyone,

I'm not used to coding in VBScript, so I hope someone can help me out with this problem. Below is the code I write to get the members of the GAL (Global Address List) distribution list.


<html>
<head>
<script LANGUAGE="VBScript" type="text/vbscript">
CONST ServerName = "<servername>"
CONST MailBox = "<mailbox username>"

Sub Connect ()
Set cdoSession = CreateObject("MAPI.Session")
Set rdoSession = CreateObject("Redemption.RDOSession")
Set objOutlook = CreateObject("Outlook.Application")
Set nsOutlook = objOutlook.GetNamespace("MAPI")

cdoSession.Logon , , False, False, , True, ServerName & vbLf & MailBox
rdoSession.LogonExchangeMailbox MailBox, ServerName
End Sub

Sub Disconnect ()
cdoSession.Logoff
rdoSession.Logoff

Set cdoSession = nothing
Set rdoSession = nothing
End Sub

Function GetDistLists (strName)
Dim oAddrList
Dim oDistList

Set oAddrList = nsOutlook.AddressLists("Global Address List")
Set oDistList = oAddrList.AddressEntries(strName)

GetDistLists = oDistList
End Function

Sub viewMembers (strGroup)
Dim oDistList
Dim oListMember
Dim strMember

Set oDistList = GetDistLists(strGroup)
For Each oListMember In oDistList.Members
strMember = strMember & oListMember.Name & vbCrLf
Next
MsgBox strMember
End Sub
</script>
</head>

<body onLoad="Connect" onUnload="Disconnect">
<form name="formCDO">
View Members of this Distribution List:
<input type="text" name="txtGroup" size="20" />
<input type="button" value="View Members" onclick="viewMembers document.formCDO.txtGroup.value" />
</form>
</body>
</html>


When I run this code and click on the button, I get the following error:
Object Required: '[string: <group_name>]'

and I know the error is reflected from line:
Set oDistList = GetDistLists(strGroup)

but still, I don't know what causes the error.
I checked the entire website for this error message, but to no avail. Can anyone please help me with this problem? Thanks in advance.

lmf232s
11-19-2007, 02:36 PM
verify that a value is being passed into view members sub.

gpm1982
11-19-2007, 07:28 PM
verify that a value is being passed into view members sub.
I use MsgBox to see if strGroup contains a value, and it does. And if I enter some value in the textbox and click on the button (eg. "ABC"), I get the following error:


Line: 48
Char: 2
Error: Object required: '[string: "ABC"]'
Code: 0
URL: ....


Oh, by the way, I totally left out the variable declarations for cdoSession, rdoSession, objOutlook, and nsOutlook. Below is the revamped code:


<html>
<head>
<script LANGUAGE="VBScript" type="text/vbscript">
CONST ServerName = "<servername>"
CONST MailBox = "<mailbox username>"

' Added these lines, to make them global
Dim cdoSession
Dim rdoSession
Dim objOutlook
Dim nsOutlook

Sub Connect ()
Set cdoSession = CreateObject("MAPI.Session")
Set rdoSession = CreateObject("Redemption.RDOSession")
Set objOutlook = CreateObject("Outlook.Application")
Set nsOutlook = objOutlook.GetNamespace("MAPI")

cdoSession.Logon , , False, False, , True, ServerName & vbLf & MailBox
rdoSession.LogonExchangeMailbox MailBox, ServerName
End Sub

Sub Disconnect ()
cdoSession.Logoff
rdoSession.Logoff

Set cdoSession = nothing
Set rdoSession = nothing
End Sub

Function GetDistLists (strName)
Dim oAddrList
Dim oDistList

Set oAddrList = nsOutlook.AddressLists("Global Address List")
Set oDistList = oAddrList.AddressEntries(strName)

GetDistLists = oDistList
End Function

Sub viewMembers (strGroup)
Dim oDistList
Dim oListMember
Dim strMember

Set oDistList = GetDistLists(strGroup)
For Each oListMember In oDistList.Members
strMember = strMember & oListMember.Name & vbCrLf
Next
MsgBox strMember
End Sub
</script>
</head>

<body onLoad="Connect" onUnload="Disconnect">
<form name="formCDO">
View Members of this Distribution List:
<input type="text" name="txtGroup" size="20" />
<input type="button" value="View Members" onclick="viewMembers document.formCDO.txtGroup.value" />
</form>
</body>
</html>