'Always preview messages' off and ADXSelectionChange at Outlook start

Add-in Express™ Support Service
That's what is more important than anything else

'Always preview messages' off and ADXSelectionChange at Outlook start
 
S?bastien Lange




Posts: 35
Joined: 2022-09-21
Hi,

I'm listenting to ADXSelectionChange of ADXOlForm.

When Outlook starts, the event is fired with item selected in explorer. If 'Always preview messages' is on (see Reading pane options), the message is displayed and I update my form accordingly.

But if 'Always preview messages' option is off (it's the default value), Outlook shows an "empty" reading pane with message "Select an item to read", so I would like to show an empty ADXOlForm as well...
How can I detect that the item is not "fully" selected (not displayed in reading pane)? It happens only at Outlook start.

[img]https://filestore.community.support.microsoft.com/api/images/4d6e6e94-bc9b-4b0d-8759-0cfe6699af0b?upload=true[/img]

[img]https://filestore.community.support.microsoft.com/api/images/0f4c4d65-04f5-4e35-a9b5-203aba2887ec[/img]

Br,
Sebastien
Posted 03 Oct, 2022 02:27:28 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello S?bastien,

I?Â?Ð?éve tested calling this property in VBA: Application.ActiveExplorer.PreviewPane.WordEditor.

It is only available in Outlook 2016 and above. Note that the PreviewPane property/object is missing in the Outlook 2016 interop deployed with Add-in Express and with Visual Studio. That is, you?Â?Ð?éll need to access it using late binding; wrap the call in a try/catch. The logic is as follows:
- you call the PreviewPane property
- if the call fails, the property is missing and you leave
- if it returns an object, call the WordEditor property using late binding; wrap the call in a try/catch block
- if the call succeeds, the Reading Pane displays an email
- if the call fails, the Reading Pane doesn?Â?Ð?ét display an email ?Â?Ð?ã this is your case.

Release all COM objects!

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 03 Oct, 2022 04:03:30 Top
S?bastien Lange




Posts: 35
Joined: 2022-09-21
Thanks for your quick answer.

Indeed, when outlook starts, PreviewPane.WordEditor throws an exception and I can hide my form.
But then, if I click on any mail item, PreviewPane.WordEditor still throws an exception within my ADXSelectionChange handler, while preview pane shows the email.
This is only after second click that PreviewPane.WordEditor returns something...

Any idea?
Posted 03 Oct, 2022 04:37:14 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello S?bastien,

Check whether the issue occurs if you use the ADXOutlookAppEvents.SelectionChange event.

If it does, try to introduce a delay before calling PreviewPane.WordEditor; check section Wait a little; see the PDF file in the folder {Add-in Express}\Docs on your development PC. Note that ADXOlForm has the ADXPostMessage method and the ADXOlForm.ADXPostMessageReceived event. Use them to create such a delay.

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 03 Oct, 2022 05:53:39 Top
S?bastien Lange




Posts: 35
Joined: 2022-09-21
Thanks a lot! It's weird, but it works!

Is it normal that ADXOlForm.ADXSelectionChange is always fired twice for the same selected item? Yet another weird behavior of Outlook?
Posted 03 Oct, 2022 08:21:42 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Congratulations!

S?bastien Lange writes:
Is it normal that ADXOlForm.ADXSelectionChange is always fired twice for the same selected item? Yet another weird behavior of Outlook?


This is expected. You need to get the EntryId of the selected message and check whether you've already processed it or not.

The add-in Express manual contains this note:

IMPORTANT. The user may select a submitted item ?Â?Ð?ã after you click the Send button on an email, the corresponding item is moved to Outbox and marked as submitted. If the add-in reads any property of a submitted item, this makes the item non-submitted. A non-submitted item cannot be sent. For the end user, it looks like the item hangs in the Outbox folder forever. To prevent this issue, in whatever way you obtain an Outlook item, you must check whether it is submitted or not. Find how we do this in code; see the ContextInfo.GetSummaryFromOutlookItem() method.


Find the sample Outlook add-in project in https://www.add-in-express.com/creating-addins-blog/2020/07/01/sample-com-addin-projects-outlook-excel-powerpoint-word/.

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 03 Oct, 2022 09:03:15 Top