populating fields with information from the address book

  • Thread starter TmF0
  • Start date Views 1,847
Status
Not open for further replies.
T

TmF0

We currently have 2 room setup forms, which are stored in public folders. The

forms have room & meeting information ,primary and secondary contact

information, and date and time information. All of the information is

manually entered , except for the requestor's name, division and employee

which is filled in automatically when the form is opened up. I oriiginally

edited the form with the script editor, but now when a new user opens the

form it only fills in the employee name, except when I open the form it works

correctly.

In a previoius question, Sue referenced using CDO 1.21, but I don't know

what that means. She also mentioned "commenting out the On Error resume Next

statement" to help troubleshoot the issue. I am not sure what that means as

I am no programmer but am trying to resolve this OL issue. These are forms

that have been at our organization for awhile but the programmers are no

longer here and I could not find any documentation. Here is the code I think

references that functionality. Any guidance would be greatly appreciated.

'*************************************************************

'* Room set up script

'* this posts to a folder, has two click buttons which will cause messages

to be generaged

'*

'*

'*

'*************************************************************

'* global settings

'*************************************************************

dim composemode

composemode=True

dim olemsession

'*************************************************************

'* ItemRead

'* This event will only occur when an item is loaded from storage

'* thus if a new item, then composemode set in global settings remains true

'**************************************************************

Sub Item_Read()

' if this subroutine occurs, then an item was read

Composemode = False

End Sub

'******************************************************************

'* Function: Item_Open()

'* Description: On composing the form, a MAPI Session

'* logs on and calls Sub GetDefaultFields()

'* to retrieve the user's name, department

'* and phone number.

'*

'******************************************************************

Function Item_Open()

if item.size = 0 then 'if in compose mode

Set Item.userproperties("ContactPerson").value =

Application.GetNameSpace("MAPI").CurrentUser

' get ole/message session object

Set olemsession = application.CreateObject("MAPI.Session")

' logon to current session

returncode =

olemsession.Logon(application.GetNameSpace("MAPI").CurrentUser, "", False,

False, 0)

Set mypage = Item.GetInspector.ModifiedFormPages("Meeting")

Call SetDefaultFields

'Logoff the session object

olemsession.Logoff()

end if

End Function

'**********************************************************************

'* PROCEDURE: SetDefaultFields

'* DESCRIPTION: Populate employee fields on the form with information

'* retrieved about the user from the address book.

'***********************************************************************

Sub SetDefaultFields()

On Error Resume Next

Set user = olemsession.CurrentUser

'PR_DISPLAY_NAME

item.userproperties.find("ContactPerson") = user.Name

'PR_DIVISION / DEPARTMENT_NAME

item.userproperties.find("Division") = user.Fields.item(&h3a18001e)

'PR_BUSINESS_TELEPHONE_NUMBER

item.userproperties.find("ContactPhone") = user.Fields.item(&h3a08001e)

end sub
 
S

Sue Mosher [MVP]

CDO 1.21 is a programming interface used when your code calls

CreateObject("MAPI.Session"). It is not installed with Outlook 2007 and must

be downloaded from

http://www.microsoft.com/downloads/details.aspx?FamilyID=2714320d-c997-4de1-986f-24f081725d36&displaylang=en

and installed separately on each Outlook 2007 machine that needs it. If you

have an earlier version of Outlook, CDO can be installed as an optional

Outlook component from the Office setup/maintenance program.

To comment out a line of code means to put an apostrophe at the beginning of

the line, telling Outlook not to run that code statement. If you look at

your code, you'll see that many statements are such comments.

Sue Mosher

"Nat" <Nat> wrote in message

news:2CCD91E8-AF00-4F14-8E9A-F72268FE3221@microsoft.com...
> We currently have 2 room setup forms, which are stored in public folders.
> The
> forms have room & meeting information ,primary and secondary contact
> information, and date and time information. All of the information is
> manually entered , except for the requestor's name, division and employee
> which is filled in automatically when the form is opened up. I
> oriiginally
> edited the form with the script editor, but now when a new user opens the
> form it only fills in the employee name, except when I open the form it
> works
> correctly.

> In a previoius question, Sue referenced using CDO 1.21, but I don't know
> what that means. She also mentioned "commenting out the On Error resume
> Next
> statement" to help troubleshoot the issue. I am not sure what that means
> as
> I am no programmer but am trying to resolve this OL issue. These are
> forms
> that have been at our organization for awhile but the programmers are no
> longer here and I could not find any documentation. Here is the code I
> think
> references that functionality. Any guidance would be greatly appreciated.

> '*************************************************************
> '* Room set up script
> '* this posts to a folder, has two click buttons which will cause
> messages
> to be generaged
> '*
> '*
> '*
> '*************************************************************
> '* global settings
> '*************************************************************
> dim composemode
> composemode=True
> dim olemsession

> '*************************************************************
> '* ItemRead
> '* This event will only occur when an item is loaded from storage
> '* thus if a new item, then composemode set in global settings remains
> true
> '**************************************************************

> Sub Item_Read()
> ' if this subroutine occurs, then an item was read
> Composemode = False
> End Sub

> '******************************************************************
> '* Function: Item_Open()
> '* Description: On composing the form, a MAPI Session
> '* logs on and calls Sub GetDefaultFields()
> '* to retrieve the user's name, department
> '* and phone number.
> '*
> '******************************************************************
> Function Item_Open()
> if item.size = 0 then 'if in compose mode

> Set Item.userproperties("ContactPerson").value =
> Application.GetNameSpace("MAPI").CurrentUser

> ' get ole/message session object
> Set olemsession = application.CreateObject("MAPI.Session")

> ' logon to current session
> returncode =
> olemsession.Logon(application.GetNameSpace("MAPI").CurrentUser, "", False,
> False, 0)

> Set mypage = Item.GetInspector.ModifiedFormPages("Meeting")

> Call SetDefaultFields

> 'Logoff the session object
> olemsession.Logoff()

> end if

> End Function

> '**********************************************************************
> '* PROCEDURE: SetDefaultFields
> '* DESCRIPTION: Populate employee fields on the form with information
> '* retrieved about the user from the address book.
> '***********************************************************************
> Sub SetDefaultFields()
> On Error Resume Next

> Set user = olemsession.CurrentUser

> 'PR_DISPLAY_NAME
> item.userproperties.find("ContactPerson") = user.Name

> 'PR_DIVISION / DEPARTMENT_NAME
> item.userproperties.find("Division") = user.Fields.item(&h3a18001e)

> 'PR_BUSINESS_TELEPHONE_NUMBER
> item.userproperties.find("ContactPhone") = user.Fields.item(&h3a08001e)

> end sub

>
 
T

TmF0

Thanks Sue. I downloaded a CDO for a separate MS issue last May. I still

have it on a jump drive, however it does not show up in add/remove programs.

How can I tell if other PCs have the CDO?

My only confusion stems from the fact that this form seemed to work

correctly, prior to me editing some code. At least I never heard any

complaints from others if it did not. We have had OL 2007 and exchange 2007

for awhile now, if the CO was a possible issue why would it show up now?

"Sue Mosher [MVP]" wrote:


> CDO 1.21 is a programming interface used when your code calls
> CreateObject("MAPI.Session"). It is not installed with Outlook 2007 and must
> be downloaded from
> http://www.microsoft.com/downloads/details.aspx?FamilyID=2714320d-c997-4de1-986f-24f081725d36&displaylang=en
> and installed separately on each Outlook 2007 machine that needs it. If you
> have an earlier version of Outlook, CDO can be installed as an optional
> Outlook component from the Office setup/maintenance program.

> To comment out a line of code means to put an apostrophe at the beginning of
> the line, telling Outlook not to run that code statement. If you look at
> your code, you'll see that many statements are such comments.
> > Sue Mosher
> > >

> "Nat" <Nat> wrote in message
> news:2CCD91E8-AF00-4F14-8E9A-F72268FE3221@microsoft.com...
> > We currently have 2 room setup forms, which are stored in public folders.
> > The
> > forms have room & meeting information ,primary and secondary contact
> > information, and date and time information. All of the information is
> > manually entered , except for the requestor's name, division and employee
> > which is filled in automatically when the form is opened up. I
> > oriiginally
> > edited the form with the script editor, but now when a new user opens the
> > form it only fills in the employee name, except when I open the form it
> > works
> > correctly.
> > In a previoius question, Sue referenced using CDO 1.21, but I don't know
> > what that means. She also mentioned "commenting out the On Error resume
> > Next
> > statement" to help troubleshoot the issue. I am not sure what that means
> > as
> > I am no programmer but am trying to resolve this OL issue. These are
> > forms
> > that have been at our organization for awhile but the programmers are no
> > longer here and I could not find any documentation. Here is the code I
> > think
> > references that functionality. Any guidance would be greatly appreciated.
> > '*************************************************************
> > '* Room set up script
> > '* this posts to a folder, has two click buttons which will cause
> > messages
> > to be generaged
> > '*
> > '*
> > '*
> > '*************************************************************
> > '* global settings
> > '*************************************************************
> > dim composemode
> > composemode=True
> > dim olemsession
> > '*************************************************************
> > '* ItemRead
> > '* This event will only occur when an item is loaded from storage
> > '* thus if a new item, then composemode set in global settings remains
> > true
> > '**************************************************************
> > Sub Item_Read()
> > ' if this subroutine occurs, then an item was read
> > Composemode = False
> > End Sub
> > '******************************************************************
> > '* Function: Item_Open()
> > '* Description: On composing the form, a MAPI Session
> > '* logs on and calls Sub GetDefaultFields()
> > '* to retrieve the user's name, department
> > '* and phone number.
> > '*
> > '******************************************************************
> > Function Item_Open()
> > if item.size = 0 then 'if in compose mode
> > Set Item.userproperties("ContactPerson").value =
> > Application.GetNameSpace("MAPI").CurrentUser
> > ' get ole/message session object
> > Set olemsession = application.CreateObject("MAPI.Session")
> > ' logon to current session
> > returncode =
> > olemsession.Logon(application.GetNameSpace("MAPI").CurrentUser, "", False,
> > False, 0)
> > Set mypage = Item.GetInspector.ModifiedFormPages("Meeting")
> > Call SetDefaultFields
> > 'Logoff the session object
> > olemsession.Logoff()
> > end if
> > End Function
> > '**********************************************************************
> > '* PROCEDURE: SetDefaultFields
> > '* DESCRIPTION: Populate employee fields on the form with information
> > '* retrieved about the user from the address book.
> > '***********************************************************************
> > Sub SetDefaultFields()
> > On Error Resume Next
> > Set user = olemsession.CurrentUser
> > 'PR_DISPLAY_NAME
> > item.userproperties.find("ContactPerson") = user.Name
> > 'PR_DIVISION / DEPARTMENT_NAME
> > item.userproperties.find("Division") = user.Fields.item(&h3a18001e)
> > 'PR_BUSINESS_TELEPHONE_NUMBER
> > item.userproperties.find("ContactPhone") = user.Fields.item(&h3a08001e)
> > end sub
> >


>
 
S

Sue Mosher [MVP]

I have no idea what you mean by "a CDO." Microsoft unfortunately has used

the name "CDO" for several different things over the years. What you need

for Outlook 2007 code is the CDO 1.21 download at the URL I gave. Running

the .msi file in the download installs and registers the cdo.dll file.

Did you try commenting out the On Error Resume Next statement as I

suggested? That's going to give you the best picture of what errors may be

occurring as a result of the code that you've changed.

Sue Mosher

"Nat" <Nat> wrote in message

news:CC7A0D77-1C8A-47A1-B8F7-36763DD55713@microsoft.com...
> Thanks Sue. I downloaded a CDO for a separate MS issue last May. I still
> have it on a jump drive, however it does not show up in add/remove
> programs.
> How can I tell if other PCs have the CDO?

> My only confusion stems from the fact that this form seemed to work
> correctly, prior to me editing some code. At least I never heard any
> complaints from others if it did not. We have had OL 2007 and exchange
> 2007
> for awhile now, if the CO was a possible issue why would it show up now?

> "Sue Mosher [MVP]" wrote:
>
> > CDO 1.21 is a programming interface used when your code calls
> > CreateObject("MAPI.Session"). It is not installed with Outlook 2007 and
> > must
> > be downloaded from
> > http://www.microsoft.com/downloads/details.aspx?FamilyID=2714320d-c997-4de1-986f-24f081725d36&displaylang=en
> > and installed separately on each Outlook 2007 machine that needs it. If
> > you
> > have an earlier version of Outlook, CDO can be installed as an optional
> > Outlook component from the Office setup/maintenance program.
>

>> To comment out a line of code means to put an apostrophe at the beginning
> > of
> > the line, telling Outlook not to run that code statement. If you look at
> > your code, you'll see that many statements are such comments.
>

>> "Nat" <Nat> wrote in message
> > news:2CCD91E8-AF00-4F14-8E9A-F72268FE3221@microsoft.com...
> > > We currently have 2 room setup forms, which are stored in public
> > > folders.
> > > The
> > > forms have room & meeting information ,primary and secondary contact
> > > information, and date and time information. All of the information is
> > > manually entered , except for the requestor's name, division and
> > > employee
> > > which is filled in automatically when the form is opened up. I
> > > oriiginally
> > > edited the form with the script editor, but now when a new user opens
> > > the
> > > form it only fills in the employee name, except when I open the form it
> > > works
> > > correctly.
> >> > In a previoius question, Sue referenced using CDO 1.21, but I don't
> > > know
> > > what that means. She also mentioned "commenting out the On Error resume
> > > Next
> > > statement" to help troubleshoot the issue. I am not sure what that
> > > means
> > > as
> > > I am no programmer but am trying to resolve this OL issue. These are
> > > forms
> > > that have been at our organization for awhile but the programmers are
> > > no
> > > longer here and I could not find any documentation. Here is the code I
> > > think
> > > references that functionality. Any guidance would be greatly
> > > appreciated.
> >> > '*************************************************************
> > > '* Room set up script
> > > '* this posts to a folder, has two click buttons which will cause
> > > messages
> > > to be generaged
> > > '*
> > > '*
> > > '*
> > > '*************************************************************
> > > '* global settings
> > > '*************************************************************
> > > dim composemode
> > > composemode=True
> > > dim olemsession
> >> > '*************************************************************
> > > '* ItemRead
> > > '* This event will only occur when an item is loaded from storage
> > > '* thus if a new item, then composemode set in global settings remains
> > > true
> > > '**************************************************************
> >> > Sub Item_Read()
> > > ' if this subroutine occurs, then an item was read
> > > Composemode = False
> > > End Sub
> >>> > '******************************************************************
> > > '* Function: Item_Open()
> > > '* Description: On composing the form, a MAPI Session
> > > '* logs on and calls Sub GetDefaultFields()
> > > '* to retrieve the user's name, department
> > > '* and phone number.
> > > '*
> > > '******************************************************************
> > > Function Item_Open()
> > > if item.size = 0 then 'if in compose mode
> >> > Set Item.userproperties("ContactPerson").value =
> > > Application.GetNameSpace("MAPI").CurrentUser
> >> > ' get ole/message session object
> > > Set olemsession = application.CreateObject("MAPI.Session")
> >> > ' logon to current session
> > > returncode =
> > > olemsession.Logon(application.GetNameSpace("MAPI").CurrentUser, "",
> > > False,
> > > False, 0)
> >> > Set mypage = Item.GetInspector.ModifiedFormPages("Meeting")
> >> > Call SetDefaultFields
> >> > 'Logoff the session object
> > > olemsession.Logoff()
> >> > end if
> >> > End Function
> >> > '**********************************************************************
> > > '* PROCEDURE: SetDefaultFields
> > > '* DESCRIPTION: Populate employee fields on the form with information
> > > '* retrieved about the user from the address book.
> > > '***********************************************************************
> > > Sub SetDefaultFields()
> > > On Error Resume Next
> >> > Set user = olemsession.CurrentUser
> >> > 'PR_DISPLAY_NAME
> > > item.userproperties.find("ContactPerson") = user.Name
> >> > 'PR_DIVISION / DEPARTMENT_NAME
> > > item.userproperties.find("Division") = user.Fields.item(&h3a18001e)
> >> > 'PR_BUSINESS_TELEPHONE_NUMBER
> > > item.userproperties.find("ContactPhone") = user.Fields.item(&h3a08001e)
> >> > end sub
> >>> >

>

>
>>
 
T

TmF0

, soThanks Sue,

last year while testing Vista and OL 07, we noticed that some of our older

custom forms did not work so someone had told me to download the current

version of the CDO to resolve the issue. I am not sure if it was 1.21, but

it seemed to resolve that issue. I downloaded CDO 1.21 from your link and

saved it over the previous version. I sent that to our tech support to test

and I believe they were going to push it out to all the user PCs via Altiris

once testing was completed. On the few outlook profiles they tested, ti

worked so thanks very much for your assistance. I have not commented out the

on error resume statements yet, as I wanted to see if the CDO 1.21 would

resolve the issue first.

On a different note, I know you write a lot of books regarding outlook and I

was wondering if your books were geared more towards programmers or wannabes

like me. Although no programmer (obviously), I would be interested in

learning more about Outlook & how the forms work. It would be nice to know if

there were other, or possibly better, ways we could benefit from Outlook.

Thanks so much for your assistance with this.

"Sue Mosher [MVP]" wrote:


> I have no idea what you mean by "a CDO." Microsoft unfortunately has used
> the name "CDO" for several different things over the years. What you need
> for Outlook 2007 code is the CDO 1.21 download at the URL I gave. Running
> the .msi file in the download installs and registers the cdo.dll file.

> Did you try commenting out the On Error Resume Next statement as I
> suggested? That's going to give you the best picture of what errors may be
> occurring as a result of the code that you've changed.
> > Sue Mosher
> > >

> "Nat" <Nat> wrote in message
> news:CC7A0D77-1C8A-47A1-B8F7-36763DD55713@microsoft.com...
> > Thanks Sue. I downloaded a CDO for a separate MS issue last May. I still
> > have it on a jump drive, however it does not show up in add/remove
> > programs.
> > How can I tell if other PCs have the CDO?
> > My only confusion stems from the fact that this form seemed to work
> > correctly, prior to me editing some code. At least I never heard any
> > complaints from others if it did not. We have had OL 2007 and exchange
> > 2007
> > for awhile now, if the CO was a possible issue why would it show up now?
> > "Sue Mosher [MVP]" wrote:
> >
> >> CDO 1.21 is a programming interface used when your code calls
> >> CreateObject("MAPI.Session"). It is not installed with Outlook 2007 and
> >> must
> >> be downloaded from
> >> http://www.microsoft.com/downloads/details.aspx?FamilyID=2714320d-c997-4de1-986f-24f081725d36&displaylang=en
> >> and installed separately on each Outlook 2007 machine that needs it. If
> >> you
> >> have an earlier version of Outlook, CDO can be installed as an optional
> >> Outlook component from the Office setup/maintenance program.
> >
> >> To comment out a line of code means to put an apostrophe at the beginning
> >> of
> >> the line, telling Outlook not to run that code statement. If you look at
> >> your code, you'll see that many statements are such comments.
> >
> >> "Nat" <Nat> wrote in message
> >> news:2CCD91E8-AF00-4F14-8E9A-F72268FE3221@microsoft.com...
> >> > We currently have 2 room setup forms, which are stored in public
> >> > folders.
> >> > The
> >> > forms have room & meeting information ,primary and secondary contact
> >> > information, and date and time information. All of the information is
> >> > manually entered , except for the requestor's name, division and
> >> > employee
> >> > which is filled in automatically when the form is opened up. I
> >> > oriiginally
> >> > edited the form with the script editor, but now when a new user opens
> >> > the
> >> > form it only fills in the employee name, except when I open the form it
> >> > works
> >> > correctly.
> >> >> > In a previoius question, Sue referenced using CDO 1.21, but I don't
> >> > know
> >> > what that means. She also mentioned "commenting out the On Error resume
> >> > Next
> >> > statement" to help troubleshoot the issue. I am not sure what that
> >> > means
> >> > as
> >> > I am no programmer but am trying to resolve this OL issue. These are
> >> > forms
> >> > that have been at our organization for awhile but the programmers are
> >> > no
> >> > longer here and I could not find any documentation. Here is the code I
> >> > think
> >> > references that functionality. Any guidance would be greatly
> >> > appreciated.
> >> >> > '*************************************************************
> >> > '* Room set up script
> >> > '* this posts to a folder, has two click buttons which will cause
> >> > messages
> >> > to be generaged
> >> > '*
> >> > '*
> >> > '*
> >> > '*************************************************************
> >> > '* global settings
> >> > '*************************************************************
> >> > dim composemode
> >> > composemode=True
> >> > dim olemsession
> >> >> > '*************************************************************
> >> > '* ItemRead
> >> > '* This event will only occur when an item is loaded from storage
> >> > '* thus if a new item, then composemode set in global settings remains
> >> > true
> >> > '**************************************************************
> >> >> > Sub Item_Read()
> >> > ' if this subroutine occurs, then an item was read
> >> > Composemode = False
> >> > End Sub
> >> >> >> > '******************************************************************
> >> > '* Function: Item_Open()
> >> > '* Description: On composing the form, a MAPI Session
> >> > '* logs on and calls Sub GetDefaultFields()
> >> > '* to retrieve the user's name, department
> >> > '* and phone number.
> >> > '*
> >> > '******************************************************************
> >> > Function Item_Open()
> >> > if item.size = 0 then 'if in compose mode
> >> >> > Set Item.userproperties("ContactPerson").value =
> >> > Application.GetNameSpace("MAPI").CurrentUser
> >> >> > ' get ole/message session object
> >> > Set olemsession = application.CreateObject("MAPI.Session")
> >> >> > ' logon to current session
> >> > returncode =
> >> > olemsession.Logon(application.GetNameSpace("MAPI").CurrentUser, "",
> >> > False,
> >> > False, 0)
> >> >> > Set mypage = Item.GetInspector.ModifiedFormPages("Meeting")
> >> >> > Call SetDefaultFields
> >> >> > 'Logoff the session object
> >> > olemsession.Logoff()
> >> >> > end if
> >> >> > End Function
> >> >> > '**********************************************************************
> >> > '* PROCEDURE: SetDefaultFields
> >> > '* DESCRIPTION: Populate employee fields on the form with information
> >> > '* retrieved about the user from the address book.
> >> > '***********************************************************************
> >> > Sub SetDefaultFields()
> >> > On Error Resume Next
> >> >> > Set user = olemsession.CurrentUser
> >> >> > 'PR_DISPLAY_NAME
> >> > item.userproperties.find("ContactPerson") = user.Name
> >> >> > 'PR_DIVISION / DEPARTMENT_NAME
> >> > item.userproperties.find("Division") = user.Fields.item(&h3a18001e)
> >> >> > 'PR_BUSINESS_TELEPHONE_NUMBER
> >> > item.userproperties.find("ContactPhone") = user.Fields.item(&h3a08001e)
> >> >> > end sub
> >> >> >> >
> >
> >>


>
 
S

Sue Mosher [MVP]

My books were written with the beginner to intermediate Outlook programmer

in mind. Thanks for asking!

Sue Mosher

"Nat" <Nat> wrote in message

news:9F2B577C-EE21-4EA3-A8F1-4687181D67A8@microsoft.com...

> On a different note, I know you write a lot of books regarding outlook and
> I
> was wondering if your books were geared more towards programmers or
> wannabes
> like me. Although no programmer (obviously), I would be interested in
> learning more about Outlook & how the forms work. It would be nice to know
> if
> there were other, or possibly better, ways we could benefit from Outlook.
 
Status
Not open for further replies.
Top