Problem with controls on Contacts page

D

David

Hi All,
I have created a COM-AddIn with VB6 for Outlook 2000 with a custom
Contacts form. I am running Windows XP. I have button on the standard tool
bar, when clicked, it loops through all the displayed phone number for each
contact item and updates them. But I get a "Object value not set" error. The
Phone1Label, Phone2Label, Phone3Label and Phone4Label are part of the
standard contacts form, so I am not sure why I get the error.

Dim j As Integer
Dim ctrlLabel
For Each myitem In objFolder.Items
For j = 1 To 4
'gets the control that displays the phone type
'get error here
Set ctrlLabel =
myitem.GetInspector.ModifiedFormPages("General").Controls("Phone" & j &
"Label")
... do other stuff ...
Next
Next
item.Save
Next

Thanks for any help.
 
K

Ken Slovak - [MVP - Outlook]

Item is not intrinsically defined for anything other than code in an Outlook
form. You need to define that somewhere. You are only showing a snippet of
your code but are you getting an Inspector object and is it the correct one,
are you instantiating the folder and have you modified the General tab of
the contacts form? ModifiedFormPages isn't available unless the page has
been modified.
 
D

David

Ken,
I am getting the correct folder and declare myitem as shown here:
Dim myitem As ContactItem
Dim objFolder As MAPIFolder
Set objFolder =
oHostApp.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)

Also myitem is being set correctly because I can see the FullName
parameter change in my watch window.
What do you mean "modified" the general form, are you talking about
modifying the physical layout of the form or the data in the form?
The General form is modified, I have added 4 new labels which I want to
update in the "do other stuff" part.
Maybe I am not getting the correct inspector. how do i get the correct
one?

Thanks
David
 
K

Ken Slovak - [MVP - Outlook]

MyItem.GetInspector should return the correct Inspector if MyItem is
correct. I usually use late binding when I work with controls from the
MSForms 2.0 library (the one used for Outlook form controls) and declare the
controls as Object. It works better that way. You can also break things down
somewhat, separate lines for getting the Inspector and then the Page and so
on so you can see exactly where things are going wrong.

Modified in this case refers to the form design of that tab. A tab isn't in
the ModifiedFormPages collection unless its design has been modified.
 
D

David

I broke down the statement to the following
Dim ctrlLabel As Control
Dim myInspector As Inspector
Dim myPages As Pages
Dim myGeneralPage As Object

Set myInspector = myitem.GetInspector
Set myPages = myInspector.ModifiedFormPages '
myPages.count = 0
Set myGeneralPage = myPages.item("General")
' returns Nothing
Set ctrlLabel =
myGeneralPage.Controls("Phone1Label") 'error

What I noticed is that myPages.count = 0, so myGeneralPage ends
up getting set to Nothing, hence the error I keep getting. I believe the
Inspector is correct because its caption is "[FullName] - [Custom Form
Name]". I know that I have modified the my custom contacts form and
published it. I have also deleted the contact item and created a new contact
just to make sure that the latest form was being used.

Any other ideas?
 
K

Ken Slovak - [MVP - Outlook]

According to the Object Browser Help: "Every Inspector object has a Pages
collection defined, which is empty (count 0) if the Outlook item has never
been customized before." So, if your Pages collection is empty the form you
are using hasn't been modified and therefore there are no Pages in the
ModifiedFormPages collection.

Check the MessageClass of the item. See if it has your custom message class.
And remember that you cannot access a page such as the General tab that way
unless you have actually modified the tab, for example by adding one or more
controls to it.
 

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