"Can't show non-modal form when modal..."

RobertEnglish
RobertEnglish used Ask the Experts™
on
Getting error "Can't show non-modal form when modal is displayed"

On encountering this error I loop thru the the Forms collection ("For i = 0 To Forms.Count - 1 ...")  and Print the name of each & every form loaded, however NO modal form is listed.

Is there any way of finding out what modal form this error is talking about?
OR
Is there any known issues where modal forms incorrectly unload? (in every modal form I have "Unload frmX" followed by "Set frmX = Nothing")
OR
Is there any known case where that error appears for the wrong/another reason?

Please help as I've been battling with this for 4 months!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
If you have any form opened in a Modal state then you have to close that form before any other Non_modal form can be opened. On the contrary multiple Modal forms can be opened.

There is some code in your Modal form that tries to Open or load a Non-Modal form. Check whether you are referring to some property of a Non-Modal form within the code of the modal form. If yes then this is the cause of error.

Author

Commented:
Unfortunately I am unable to find out what that modal form is, That's the problem

Commented:
The code that causes the error must be inside the modal form itself, or called from it.

At the time of the error, examine the call stack (Ctrl-L) and look at each point to find a call like

frmX.Show vbModal
or frmX.Show 1

Once you find that, it should all become clear.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
VB open form in two states:
1. Modal
2. Modeless

The best example of a Modal form would be a messagebox. Unless you close the msgbox you cant use the application.

By default VB opens Modeless forms. So unless you have opened a form by specifying constant vbModal, VB would not open a Modal form.

Modal forms are useless where we need to get an action from the user before going ahead. Ex: we want to warn the user and accept an appropiate action from him then we will open a Modal form.

Get back to me in case of any further doubts.

Author

Commented:
Sethi, thanks, but I fully understand what modal forms are and how they work. I need to find out why I'm getting "Cannot show non-modal form when modal form is being displayed" when I cannot find evidence of any modal forms displayed or loaded

Commented:
Sorry, misread your comment. Press Edit> Find> Select Search Option as "Current Project" and then search for the word "Modal" in your project.  You will come to know the form that you are opening as Modal. Some code in that form will be the root cause of this problem.

Commented:
Robert,
Can we assume that you are certain that you are certain that no modal forms have EVER been launched in the history of your running application?

I've had wierd things happen when you only .HIDE a form from within itself, but not destroy it with 'Unload' and SET MyForm = Nothing when you are finished.  At least this could be a clue for you.

Also, is this an MDI application?

Doug

Author

Commented:
Doug, Yes it is an MDI application.

There are modal forms launched & closed with the app, but I just can't find out which form this error is referring to, as I'm unable to replicate when the project is running from VB. Instead I log the contents of the Forms collection, but no modal form is listed.

Commented:
Ah, so you cannot reproduce it in the VB IDE!  Can you reproduce it yourself, or is this something that happens only to users occasionally?

Author

Commented:
This happens occasionally for users on Win2000 sp3, NT4 sp6a & Win98se platforms. Once it starts any modal form that is opened thereafter behaves as if disabled (only closed by Escape key) yet non-modal forms act normally.
Private Const GWL_EXSTYLE As Long = (-20)
Private Const WS_EX_APPWINDOW As Long = &H40000
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long

Function IsModalForm(ByVal frm As Form) As Boolean
    IsModalForm = ((GetWindowLong(frm.hwnd, GWL_EXSTYLE) And WS_EX_APPWINDOW) = WS_EX_APPWINDOW)
End Function
Author of the Year 2009

Commented:
Hi RobertEnglish,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

RobertEnglish, Please DO NOT accept THIS comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial