Populating a combo box from Outlook contacts

L

lizcole

I have sucessfully done this on a custom form and it works
on my system but does not work at the client's site. I'm
using vbscript:

Sub Item_Open()

' Sets FormPage equal to the page ("Visit Report")
Set FormPage = Item.GetInspector.ModifiedFormPages
("Visit Report")

' Sets Control to a ListBox called cboContacts
Set Control = FormPage.Controls("cboContacts")

' Assign values to the ComboBox from Outlook Contacts

' Sets an object for the application
Set olns = Application.Session
' Get the default Contacts folder
Set ConFolder = olns.GetDefaultFolder(10)
' Get the items in the folder
Set ConItems = ConFolder.Items
' Get the total items in the Contacts folder
NumItems = ConItems.Count

' Resize array to handle total no. of folder items
ReDim FullArray(NumItems-1,2)

' Loop through the items in the Contacts folder,
' filling the array with data and keeping track
' of the number of contacts found.

NumContacts = 0
For I = 1 to NumItems
Set itm = ConItems(I)
NumContacts = NumContacts + 1
FullArray(NumContacts-1,0) = itm.fullname
FullArray(NumContacts-1,1) =
itm.CompanyName
Next

' Set the control to handle 2 data columns
Control.ColumnCount = 2

' Populate the combobox

Control.List() = FullArray


End Sub


If I use a msgbox statement to display the folder name it
works but whenever I try to display a field from the first
itm even the msgbox doesn't display. Does my client have
a dll missing or some other essential setting etc?

Cheers

Liz
 
S

Sue Mosher [MVP-Outlook]

There are two major causes of code in an Outlook form not running -- 1)
security settings in Outlook 2003 and 2) the broader form script security
features introduced with the Outlook Email Security Update.

#1: Outlook 2003 includes a new setting -- turned off by default -- to allow
forms in shared mailboxes to run script. You can change the setting by
choosing Tools | Options | Other | Advanced Options and checking the box for
Allow script in shared folders. See
http://www.outlookcode.com/d/ol2003problems.htm#mailboxscript for more
information on this setting and a comparable one (on by default for public
folders).

#2: If the form runs code when you use Run This Form in design mode, but
doesn't run code after you have sent or saved an item using the form, you
probably have done something to "one-off" the form. Outlook 2003, Outlook
2002, Outlook 2000 SP2 and Outlook 2000 or 98 with the Email Security Update
will not run code on one-off forms; see
http://www.outlookcode.com/d/secforms.htm for more information on this
issue.

To ensure that a form does not one-off:

-- Make sure the "Send form definition with item" box on the (Properties)
tab of the form is *not* checked. [1]

-- For in-house corporate use with Exchange Server, publish the form to the
Organization Forms library or a public folder's forms library, as
appropriate for your application.

-- For collaboration via the Internet, publish your form to your Personal
Forms library. Save it as an .oft file and send it to other people who need
to use it with instructions to publish it with the same form name that you
used.

Many other things can cause one-off forms. If the above steps don't work on
a new item created with your form, see
http://www.slipstick.com/dev/formpub.htm#oneoff for other possible causes.

[1] Whenever you publish a message form, Outlook will suggest that you may
want to check the "Send form definition with item" box to ensure that the
recipient will have the form, especially if you're sending to someone via
the Internet. In the current Outlook security environment, this suggestion
is obsolete. Ignore it unless your form has no code behind it.


--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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