[outlook 2003] modify all contact items

A

Acaccia

I have customized a form for a contact item but how can I publicize
this form so as that all old contacts that I have in my contacts list, take
on this modifies? Infact older contacts keep default contact form.
Thank's in advance
Andrea
 
A

Acaccia

Sue Mosher said:
You need to change the MessageClass on the existing items to point to your
new form's class

Ok I've converted old message classes to the new names, but nothing happens!
To create the new form I have selected Tools->Modules->Structure from
outlook 2003 menu.
I'have modified a form tab named "My Tab" (previous was named (p.2)) and I
saved this form template in a file oft.
Then I have introduced this code on my add-in:

//... load oft file
bstrName_T =_T("MyForm.oft");
bstrName = bstrName_T.copy();
hr = m_spApp->CreateItemFromTemplate(bstrName,myFolder,(IDispatch**)
&CustomContactItem);
if(FAILED(hr)) {
AfxMessageBox("Failed to load outlook form template");
}

//this code add an item MyForm to contacts list*************
CustomContactItem->get_FormDescription(&CustomFormDescription);
bstrName_T = _T("MyForm");
bstrName = bstrName_T.copy();
CustomFormDescription->put_Name(bstrName);
Outlook::OlFormRegistry ofr = olFolderRegistry;
CustomFormDescription->PublishForm(ofr,myFolder);
Outlook::OlInspectorClose oic = olSave;
CustomContactItem->Close(oic);

//****************************************************

CComPtr <Outlook::_NameSpace> olNs;
CComQIPtr <Outlook::_Items> spItems;
CComQIPtr <Outlook::MAPIFolder> oContacts;
Outlook::OlDefaultFolders enumODF = olFolderContacts;

spApp->GetNamespace(bstrName,&olNs);
olNs->GetDefaultFolder(enumODF,&oContacts);

BSTR oldMsgClass,newMsgClass;

_bstr_t oldMsgClass_T (_T("IPM.Contact"));
oldMsgClass = oldMsgClass_T.copy();

_bstr_t newMsgClass_T (_T("IPM.Contact.MyForm"));
newMsgClass = newMsgClass_T.copy();

oContacts->get_Items(&spItems);
long ItemCount;
spItems->get_Count(&ItemCount); //get number of contact items

for (int n = 1; n<=ItemCount;n++) {
CComVariant nItem (n);
IDispatch* itm;
hr = spItems->Item(nItem,&itm);
if (FAILED(hr)) {
AfxMessageBox("Error converting items (get item)");
break;
}
CComQIPtr <Outlook::_ContactItem> spItem;
spItem = itm;

BSTR curMsgClass;
spItem->get_MessageClass(&curMsgClass);
if (FAILED(hr)) {
AfxMessageBox("Error converting items (message class)");
break;
}
CString* curMsgClassStr = ToCString(curMsgClass); //conversion from BSTR
to CString
CString* oldMsgClassStr = ToCString(oldMsgClass); //conversion from BSTR
to CString

if (curMsgClassStr->Compare(*oldMsgClassStr) ==0) {
spItem->put_MessageClass(newMsgClass);
spItem->Save();
AfxMessageBox("Item Converted");
}
}
AfxMessageBox("Conversion finished");

The conversion process seem works fine, in fact when I read MessageClass of
contact items with Oulook Spy I obtain "IPM.Contact.MyForm". But the look of
items is the same of default "IPM.Contact"...
Where I'm wrong?

Bye
Andrea
 
S

Sue Mosher [MVP-Outlook]

Can you create an item manually with your new form?

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



Acaccia said:
"Sue Mosher [MVP-Outlook]" <[email protected]> ha scritto nel
messaggio
You need to change the MessageClass on the existing items to point to
your
new form's class

Ok I've converted old message classes to the new names, but nothing
happens!
To create the new form I have selected Tools->Modules->Structure from
outlook 2003 menu.
I'have modified a form tab named "My Tab" (previous was named (p.2)) and I
saved this form template in a file oft.
Then I have introduced this code on my add-in:

//... load oft file
bstrName_T =_T("MyForm.oft");
bstrName = bstrName_T.copy();
hr = m_spApp->CreateItemFromTemplate(bstrName,myFolder,(IDispatch**)
&CustomContactItem);
if(FAILED(hr)) {
AfxMessageBox("Failed to load outlook form template");
}

//this code add an item MyForm to contacts list*************
CustomContactItem->get_FormDescription(&CustomFormDescription);
bstrName_T = _T("MyForm");
bstrName = bstrName_T.copy();
CustomFormDescription->put_Name(bstrName);
Outlook::OlFormRegistry ofr = olFolderRegistry;
CustomFormDescription->PublishForm(ofr,myFolder);
Outlook::OlInspectorClose oic = olSave;
CustomContactItem->Close(oic);

//****************************************************

CComPtr <Outlook::_NameSpace> olNs;
CComQIPtr <Outlook::_Items> spItems;
CComQIPtr <Outlook::MAPIFolder> oContacts;
Outlook::OlDefaultFolders enumODF = olFolderContacts;

spApp->GetNamespace(bstrName,&olNs);
olNs->GetDefaultFolder(enumODF,&oContacts);

BSTR oldMsgClass,newMsgClass;

_bstr_t oldMsgClass_T (_T("IPM.Contact"));
oldMsgClass = oldMsgClass_T.copy();

_bstr_t newMsgClass_T (_T("IPM.Contact.MyForm"));
newMsgClass = newMsgClass_T.copy();

oContacts->get_Items(&spItems);
long ItemCount;
spItems->get_Count(&ItemCount); //get number of contact items

for (int n = 1; n<=ItemCount;n++) {
CComVariant nItem (n);
IDispatch* itm;
hr = spItems->Item(nItem,&itm);
if (FAILED(hr)) {
AfxMessageBox("Error converting items (get item)");
break;
}
CComQIPtr <Outlook::_ContactItem> spItem;
spItem = itm;

BSTR curMsgClass;
spItem->get_MessageClass(&curMsgClass);
if (FAILED(hr)) {
AfxMessageBox("Error converting items (message class)");
break;
}
CString* curMsgClassStr = ToCString(curMsgClass); //conversion from BSTR
to CString
CString* oldMsgClassStr = ToCString(oldMsgClass); //conversion from BSTR
to CString

if (curMsgClassStr->Compare(*oldMsgClassStr) ==0) {
spItem->put_MessageClass(newMsgClass);
spItem->Save();
AfxMessageBox("Item Converted");
}
}
AfxMessageBox("Conversion finished");

The conversion process seem works fine, in fact when I read MessageClass
of
contact items with Oulook Spy I obtain "IPM.Contact.MyForm". But the look
of
items is the same of default "IPM.Contact"...
Where I'm wrong?

Bye
Andrea
 
A

Acaccia

Sue Mosher said:
Can you create an item manually with your new form?

uhmmm... I don't have my new form in Actions menu (new MyForm field). If I
try to create a new contact form, outlook use default IPM.Contact...Maybe
because I never have publicized my form, I exclusively saved it... but this
is what I want... I shall to distribute my form to other persons
automatically loading an oft file.

Andrea
 
S

Sue Mosher [MVP-Outlook]

Where did you publish the form? What's the original issue here? The
newsgroup interface you are using apparently does not quote earlier messages
in the thread, making your latest message so short on detail that you risk
not getting the answer you're looking for. Please take the time to quote the
original message.

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



Acaccia said:
"Sue Mosher [MVP-Outlook]" <[email protected]> ha scritto nel
messaggio
Can you create an item manually with your new form?

uhmmm... I don't have my new form in Actions menu (new MyForm field). If I
try to create a new contact form, outlook use default IPM.Contact...Maybe
because I never have publicized my form, I exclusively saved it... but
this
is what I want... I shall to distribute my form to other persons
automatically loading an oft file.

Andrea
 

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