Getting recipients username from their display name

N

nYssa

Hi,

I have a custom appointment outlook form, and I am wanting to pop up a
message if a resource is invited to the appointment. I have the code
to check whether a resource has been invited:

Function RecipCountNoResource()
Dim objRecip
Dim intCount
Const olResource = 3
intCount = 0
Set colRecips = Item.Recipients
For Each objRecip In Item.Recipients
If objRecip.Type <> olResource Then
intCount = intCount + 1
End If
Next
RecipCountNoResource = intCount
Set objRecip = Nothing
End Function

HOWERVER: What I want to do is to check if the resource that is
invited
belongs to a particular group. I have been told that the only way to
do this
is creating a MAPI session in order to get the username. But I haven't
been
able to find enough information to do it. Once I have the code to get
the
username based on the recipient, then I can check if it is a
particular
group, which I can do using the following code:

Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")

strDomain = "mydomain.com"
strUser = "nmillin"

Set oUser = GetObject("WinNT://" & strDomain & "/" & strUser)

If MemberOf("Solutions", oUser) = true then
If objRecip
intCount = intCount + 1
End If
End If

However at the moment the user name is hard coded. So my question is
again,
how do I get a recipients username (ie. jbloggs) using CDO/MAPI.
 
N

nYssa

UPDATE:

I have gotten this to work on my test environment. My test environment is a
windows server 2000 with exchange and Office 2000. However when I try and run
the same code on my production machine, it fails. My prod machine is a win xp
pro, office 2003 desktop. I have changed the domain name and group, yet when
it runs the GetObject("LDAP://...") line it fails. The error message I get in
Visual Studio 2003 is "unknown exception" and no error number or other
details. CDO has been installed on my test machine, and uninstalled, with
both times the outlook form still working. This form needs to run on multiple
client machines so does the GetObject not work on client machines?

This is the code:

Function RecipCountNoResource()
Dim objRecip
Dim intCount
Const olResource = 3
intCount = 0
Set colRecips = Item.Recipients
For Each objRecip In Item.Recipients
If objRecip.Type = olResource Then
'GET the ALIAS of the resource that we have selected
'To see IF WE ARE INVITING A MEETING ROOM

strNamValue = objRecip.Name
strDisplayName = objRecip.Name
Set oUser = GetObject ("LDAP://cn=" & strDisplayName &
",cn=Users,dc=mydomain,dc=com")

if MemberOf("Meeting Room", oUser) = true then
intCount = intCount + 1
end if

End if
Next
RecipCountNoResource = intCount
Set objRecip = Nothing
End Function

Thanks,
nYssa
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top