Opening instead of closing???

Hi,
I have a ListBox which contains a contextual menu. When I use the code below - all works perfectly. It closes certain windows if they are open, and opens the window selected by the user.

[code] Select Case hititem.text
case “Add a New Choice”
frm_Search.Close
win_Add.ShowModal
case “Edit or Delete the Selected Choice”
frm_Search.Close
win_Edit.ShowModal
case “Search Choices”
win_Add.Close
frm_Search.ShowModal
case “View All Choices”
frm_Search.Close
win_Add.Close
win_Main.Open
End select

Return True[/code]

HOWEVER - the impossible seems to happen when I add the code below to the 1st, 3rd and 4th Cases.
It causes ALL of the cases to OPEN the “win_Edit” window - instead of closing it, and opening the appropriate window ???

win_Edit.Close

It seems impossible and I am totally perplexed.
Can anyone shed any light or ideas?

Thank you all in advance.

Sounds like a side-effect of Implicit window instantiation which allows you to refer to your windows directly by their name. Although convenient, it can lead to this confusing behavior as projects get more complex.

You’ll instead want to create your own instances of your windows (like you would for any other object) and deal with the windows that way.

So something more like this:

Dim editWindow As win_Edit editWindow.Show

Then to close the window you can call:

editWindow.Show

Bit confused as I am only a part time user :frowning:

So I need to de-select the Implicit instance in the inspector.
Then add the first section of code you provided.

Also, should the last piece of code you kindly provided be editWindow.Close ?

Thank you for your patience. :slight_smile: