Focus problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.
 
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
 
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.
 
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
 
I'm lost too. I've never seen what you describe happen unless the code is
setting focus elsewhere. Just accessing Selection does not change what is
selected. Something is missing in the description of what your code is
doing.
 
Here is my function:
Private Sub oMailItem_Current() Handles oExplorer.SelectionChange
If oExplorer.Selection.Count > 0 Then
If TypeOf oExplorer.Selection.Item(1) Is Outlook.MailItem Then
oMailItem = CType(oExplorer.Selection.Item(1),
Outlook.MailItem)
End If
End If
End Sub

ASA the pointer is executiong the "if typeof oExplorer.selection... then"
the focus is lost for an unexistant mail open.

I so don't get it., it should have something I could do?
First I thought that oExplorer.Activate() will be ok but the problem with
that it's when I'm opening for real a mail the focus is lost.

I don't know what to do and I have to find out something

Nobody has been confronted with this before?
Ken Slovak - said:
I'm lost too. I've never seen what you describe happen unless the code is
setting focus elsewhere. Just accessing Selection does not change what is
selected. Something is missing in the description of what your code is
doing.




Kenny said:
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
 
I found a way to let me keep going on the project here is what I have done.

Private Sub oMailItem_Current() Handles oExplorer.SelectionChange
Try
Tempo = False
If oExplorer.Selection.Count > 0 Then
If TypeOf oExplorer.Selection.Item(1) Is Outlook.MailItem Then
oMailItem = CType(oExplorer.Selection.Item(1),
Outlook.MailItem)
If Tempo Then
oExplorer.Activate()
End If
End If
End If
End Sub

The tempo var can only be true when you first click on a mail that means
when you intercept the NewInspector function with an handles.

In that handles I put Tempo to true, so that way it would be true only for
every first clic for each mail.

In the case some one will have the real solution please post it here

Thank you

Kenny said:
Here is my function:
Private Sub oMailItem_Current() Handles oExplorer.SelectionChange
If oExplorer.Selection.Count > 0 Then
If TypeOf oExplorer.Selection.Item(1) Is Outlook.MailItem Then
oMailItem = CType(oExplorer.Selection.Item(1),
Outlook.MailItem)
End If
End If
End Sub

ASA the pointer is executiong the "if typeof oExplorer.selection... then"
the focus is lost for an unexistant mail open.

I so don't get it., it should have something I could do?
First I thought that oExplorer.Activate() will be ok but the problem with
that it's when I'm opening for real a mail the focus is lost.

I don't know what to do and I have to find out something

Nobody has been confronted with this before?
Ken Slovak - said:
I'm lost too. I've never seen what you describe happen unless the code is
setting focus elsewhere. Just accessing Selection does not change what is
selected. Something is missing in the description of what your code is
doing.




Kenny said:
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
 
There must be some sort of Interop bug with that, it won't happen in VBA
code or other unmanaged code.

Try this:

If oExplorer.Selection.Item(1).Class = olMail Then
 
This line is not accepted, I replace olMail by something real like my object
or my class, but still not working.

The error is generate by the NewInspector event, but not the one you can
modify, because if you desactivate it the error is still here. The one by
defaut that you can't change because you cant access it, so the only is the
way I'have explain earlier.

Thank you
 
Try fully qualifying olMail:

If oExplorer.Selection.Item(1).Class = Outlook.OlObjectClass.olMail Then

Aside from that I have no idea what you just said. I understood none of it,
sorry.
 
Back
Top