Focus problem

K

Kenny

Hi,
here is what happening on OL2003 with VB:

I have this function:
Private Sub oMailItem_Current() Handles oExplorer.SelectionChange
oMailItem = oExplorer.Selection.Item(1)
End Sub

For each click on a new mail the focus is lost! I dont understand why, and
that only happen when I attribute oExplorer.Selection.Item(1) to a variable.

Somebody could help me on that problem please

Thank you
 
K

Ken Slovak - [MVP - Outlook]

Do you mean the selection the user just made is no longer selected? Using
the Selection collection is read-only, you can't make selections and you
can't unselect part or all of the selection. Just referencing the collection
or assigning it to an item should not have any effect on what was selected.

In your code you should however first be checking to see if Selection.Count
0 and also checking that what's selected is actually a mail item before
assigning Selection(1) to a mail item.
 
K

Kenny

Thanks for the advices for a better coding I did what you said.

But I still have my problem, when I click on a mail for the first time the
selection is on this mail but the focus is lost from outlook so the selection
is brown. But any click after on the same mail the focus will be ok on the
mail the selection is blue like normal act.

I find out that when I put this
oExplorer.Activate()
the focus is back, so it's kind of resolve but we can still see that the
focus is lost and then come back.

Do you have any idea where that problem is from, thank you for your help
 
K

Ken Slovak - [MVP - Outlook]

I have no idea other than it sounds like something is putting focus into
another window rather than the Explorer window. Are you opening any dialogs
or switching to another window in some way? Are you making any Win32 API
calls that could switch window focus?

What you describe is not what normally happens when Explorer.Selection is
accessed.
 
K

Kenny

No I'm doing nothing but this handles selectionchange.

I found something else on this probleme, when it occured if I press
[ALT]+[TAB] to see where the focus is from, it's from the mail like it's open
but it's not! Because I just made one click on the mail selection and also if
I clic somewhere else or if I clic another time on the mail selection this
won't happen anymore, also it's impossible to find the mail opened in the
task bar.

So I'm kind of lost with that weird problem
 
Top