WindowCount = 0, but I have an open window…

I set the code below in window’s CancelClose event (with a set of boolean to set its excecution only when the user ask for the application to quit).

For Win_Idx = WindowCount To 1 If Window(Win_Idx) IsA wMain Then

But the second If is always false even when I see one or more (instances of) wMain.

PS: I had to move the code from Window.Close to Window.CancelClose because in Window.Close, WindowCount was always 0 even if I still saw it ! (behind a MsgBox !).

Ideas on what error I am doing ?

You should use DownTo not To.

Thanks Simon.

I saw that after I sent the above text. Worst: in the comments I removed (so, not above), I explained why I wrote DownTo !!!

I may be tired !!!

Talking about casting: I have no problem to cast controls on a window, but in that case I may have a blockage…

And I had Bok’s page open ( casting ).
And I read it !

Window() is zero-based, so if you are actually using DownTo, you will skip the foremost window. Was that your intent?

And you cast a window just like you would a control.

   if Window(Win_Idx) ISA wMain then
       wMain(Window(Win_Idx)).TextField1.Text = "x"
For Win_Idx = WindowCount-1 DownTo 0
     If Window(Win_Idx) IsA wMain Then

Thank you all.