> First you must publish your custom form with its custom message class. Then
> in NewInspector or really more properly in the first Activate event for that
> Inspector you can set the message class of the opened item to your custom
> message class. You can test for a new item by using
> Inspector.CurrentItem.Size which should be 0 for new items or by using
> ..EntryID, which I prefer and will be a null string until the item has been
> saved.
>
> Don't test for that in NewInspector, in that event test for MessageClass or
> Class only, most properties of items in the Inspector aren't there or valid
> in NewInspector. Once Activate fires you can test for properties of the
> item.
>
> --
> Ken Slovak
> [MVP - Outlook]
>
http://www.slovaktech.com> Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
> Reminder Manager, Extended Reminders, Attachment Options
>
http://www.slovaktech.com/products.htm>
>
> "Tom at GSD" <TomatGSD[ at ]discussions.microsoft.com> wrote in message
> news:9D78D7C7-718D-4F72-A49D-2C2722D0A0D3[ at ]microsoft.com...
> > Hi,
> >
> > I have tried several ways (lates code snippet is at the end of the
> > message)
> > and have observered many questions all over the web - but none of the code
> > snippets seem to apply to my environment exactly. The problem is simple
> > ...when I "open" an "existing" contact I want to add a couple text boxes
> > and
> > command buttons to the "general" tab. So I figured I would design a custom
> > contacts form and save it which I did. Ultimately I want to capture the
> > new
> > inspector event and replace the default contacts form (IPM.Contact) with
> > my
> > form and populate the existing data into my new form, plus add new
> > information to the new text boxes that I created.
> >
> > I found some sample code at
> >
http://www.codeproject.com/com/OutlookForms.asp> > and I thought I would be able to use that code within the "OnNewInspector"
> > event. No matter what I do I cannot get the new form to load. the default
> > form keeps loading. I do want to use the default form for creating NEW
> > contacts, however to open or view the contact I want to use my custom
> > form.
> >
> > I do know that deleting or saving a form greatly affects the Outlook
> > defaults and I truly do not believe this is the correct method to employ.
> >
> > BTW - if I manually - as a user - Publish the form and make my custom form
> > the default form it does load my custom form when we want to create a new
> > contact. So the form does load for a new contact.
> >
> > The following is a code snippet that I have been playing with all day and
> > I
> > was wondering if anyone out there knows how to properly replace the
> > contacts
> > form with a custom form just for the opening and viewing and existing
> > contact?
> >
> > void __stdcall CConnect::OnNewInspector(IDispatch *
> > /*Outlook::_Inspector**/
> > Ctrl)
> > {
> > try
> > {
> > CComQIPtr<Outlook::_Inspector> pInspector(Ctrl);
> > IDispatchPtr spDisp = pInspector->GetCurrentItem();
> >
> >
> > Outlook::_ContactItemPtr spContactItem = spDisp;
> >
> > if(spContactItem != NULL)
> > {
> > bstr_t btName(_T("MAPI"));
> > CComVariant myFolder(DISP_E_PARAMNOTFOUND, VT_ERROR);
> > Outlook::_ApplicationPtr spApp = pInspector->GetApplication();
> > Outlook::_NameSpacePtr spNameSpace = spApp->GetNamespace(btName);
> >
> > Outlook::MAPIFolderPtr spContacts;
> > Outlook::OlDefaultFolders enumODF = Outlook::olFolderContacts;
> > spContacts = spNameSpace->GetDefaultFolder(enumODF);
> >
> > _bstr_t
> > btCustomFormLocation(_T("C:\\MyCustomForms\\OutlookForm\\MyContact.oft"));
> >
> > Outlook::_ContactItemPtr spCustomContactItem =
> > spApp->CreateItemFromTemplate(btCustomFormLocation, myFolder);
> >
> > Outlook::OlInspectorClose oic;
> > CComVariant varContacts(spContacts);
> >
> > _bstr_t btFormDescription(_T("IPM.Contact.MyContact"));
> >
> > Outlook::OlFormRegistry ofr = Outlook::olFolderRegistry;
> > Outlook::FormDescriptionPtr spCustomFormDescription =
> > spCustomContactItem->GetFormDescription();
> >
> > spCustomFormDescription->PutName(btFormDescription);
> > spCustomFormDescription->PublishForm(Outlook::olFolderRegistry,
> > _variant_t(spContacts, false));
> >
> > Outlook::_ItemsPtr spItems = spContacts->GetItems();
> >
> > //Outlook::OlInspectorClose oic;
> >
> > long ItemCount = spItems->GetCount();
> >
> > int changes =0;
> > oic = Outlook::olSave;
> >
> > for(int n = 1; n <= ItemCount; ++n)
> > {
> >
> > CComVariant nItem(n);
> > CComQIPtr <Outlook::_ContactItem> spItem = spItems->Item(nItem);
> >
> > if(spItem == NULL)
> > continue; //IPM.DistList
> >
> > _bstr_t curMsgClass = spItem->GetMessageClass();
> >
> > TString curMsgClassStr = (const TCHAR*)curMsgClass;
> > TString oldMsgClassStr = ADDIN_OLDMSGCLASS;
> > if(curMsgClassStr.compare(oldMsgClassStr) ==0)
> > {
> > spItem->PutMessageClass(_bstr_t(ADDIN_NEWMSGCLASS));
> > spItem->Save();
> >
> > Outlook::_ContactItemPtr spNewContactItem = spItem->Copy();
> > spNewContactItem->Close(oic);
> > spItem->Delete();
> > changes++;
> > }
> > }
> > }
> > }
> > catch(...)
> > {
> > }
> > }
> >
>
>