Visual Basic/VB >> Can't show non-modal form when modal form is displayed

by VGlt » Wed, 27 Oct 2004 22:19:10 GMT

I keep getting this error message and it comes and go's, and it is not
always on the same set of code.

Can't show non-modal form when modal form is open.

Does any body have any idea what may be cousing this?

Visual Basic/VB >> Can't show non-modal form when modal form is displayed

by alpine » Wed, 27 Oct 2004 22:39:10 GMT


On Wed, 27 Oct 2004 07:19:10 -0700, Tim




Do you have a modal form open when it happens? Are you referencing
any properties or anything else for that matter, on another form when
the error occurs?

HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don' XXXX@XXXXX.COM Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas

Visual Basic/VB >> can't show non-modal form when modal form is displayed

by admin » Sat, 25 Feb 2006 10:11:26 GMT

after i complie it, when i input the wrong password, the alert is show,
but with the error too.

how can i correct it?

thanks

--
---

http://www.letskick.net

Visual Basic/VB >> can't show non-modal form when modal form is displayed

by admin » Sat, 25 Feb 2006 10:28:32 GMT


MsgBox "Invalid Password, try again!", vbInformation, "Invalid
Password"
Unload frmSplash
Me.Show


txtPassword.SetFocus
SendKeys "{Home}+{End}"
Exit Sub


--
---

http://www.letskick.net
"" < XXXX@XXXXX.COM > : XXXX@XXXXX.COM ...

Visual Basic/VB >> can't show non-modal form when modal form is displayed

by Jeff Johnson [MVP: VB] » Sat, 25 Feb 2006 12:23:12 GMT


If you hide a modal form that was called from a modal form, you must re-show
it modally, if that's possible, and I don't remember if it is.

Visual Basic/VB >> can't show non-modal form when modal form is displayed

by Randy Birch » Sun, 26 Feb 2006 10:05:38 GMT

Yes, it is possible:

'FORM 1 code
Private Sub Command1_Click()
Form2.Show vbModal
End Sub


'FORM 2 code
Private Sub Command1_Click()
Form3.Show vbModal
End Sub


'FORM 3 code
Private Sub Form_DblClick()
Me.Hide 'or unload me
End Sub

--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/

Please reply to the newsgroups so all can participate.











If you hide a modal form that was called from a modal form, you must re-show
it modally, if that's possible, and I don't remember if it is.

Visual Basic/VB >> can't show non-modal form when modal form is displayed

by Jeff Johnson [MVP: VB] » Tue, 28 Feb 2006 11:18:46 GMT


That's not what I was talking about. I'm talking about this (which I haven't
tested):

' Form1 code
Private Sub btnShowForm2_Click()
Form2.Show vbModal
End Sub

' Form 2 code
Private Sub btnHideMe_Click()
Me.Hide
End Sub

Click btnShowForm2, then on Form2 click btnHideMe, then click btnShowForm2
again. Does Form2 come back modal? I seem to recall trying this many years
ago and it not working.

Visual Basic/VB >> can't show non-modal form when modal form is displayed

by Randy Birch » Tue, 28 Feb 2006 12:51:59 GMT

> Does Form2 come back modal?

Yes, it does.

--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/

Please reply to the newsgroups so all can participate.

Visual Basic/VB >> can't show non-modal form when modal form is displayed

by Jeff Johnson [MVP: VB] » Tue, 28 Feb 2006 12:58:11 GMT


Cool. And I also figured out what your code was demonstrating, which was my
question taken a step further.

Similar Threads

1. Can't show non-modal form when modal form is displayed

Hi everyone,

I have a modal userform that contains a button (among other controls). When 
a user clicks this button, another, modeless userform (frmHelp) should be 
displayed that contains information about the first form. It would be nice if 
users were able to access the first form while this information is still 
shown - hence the choice for modeless display.

Clicking the button results in run time error 401: Can't show non-modal form 
when modal form is displayed. Both setting the ShowModal property of frmHelp 
at design time to False and 'frmHelp.Show vbModeless' yield the error.

Is there any way to bypass this error and have the second form displayed 
modeless just the same? Displaying the first form modeless works, but in this 
way users can get at the Word document, which is out of the question.

I use Word 2003.

Thank you,
Cooz

2. Using non-modal forms when modal form displayed - Visual Basic/VB

3. Can't Show Non-Modal Form...........?

In a WebBrowser project, I have given users the option to set their
default browser to my browser i.e. whenever any HTML file is opened in
Windows Explorer, the HTML file should open with my browser. The
project also houses a CheckBox for the browser to check whether it is
the default browser or not. If not, then when the browser is run on the
first time, a MsgBox should come up asking the user if he would like to
set my browser as the default browser in his machine. If Yes, then my
browser will be set as the default browser in that machine else the
existing default browser will remain the default browser. This is how I
am checking whether my browser is the default browser or not (NOTE:
This is not my code):
visual basic code:

Private Sub Form_Load()
    If (frmBrowserOptions.chkDefault.Value = vbChecked) Then
        Call CheckDefault
    End If
End Sub

Private Sub CheckDefault()
    Dim success As Long
    Dim sBrowser As String

    'success is passed and filled in the routine
    sBrowser = GetBrowserName(success)

    'possible return values from the call returned in success
    Select Case success
    'the call succeeded
        Case Is >= ERROR_FILE_SUCCESS
            If (InStr(sBrowser, "MyBrowser.exe") = 0) Then
                If (vbYes = MsgBox("MyBrowser not default browser! Set
it as default?", vbYesNo + vbQuestion)) Then
                    Call frmBrowserOptions.cmdDefault_Click
                End If
            End If
            Exit Sub
        'other possible return values
        Case ERROR_FILE_NO_ASSOCIATION
        Case ERROR_FILE_NOT_FOUND
        Case ERROR_PATH_NOT_FOUND
        Case ERROR_BAD_FORMAT
        Case Else
    End Select
End Sub

Private Function GetBrowserName(dwFlagReturned As Long) As String
    Dim hFile As Long
    Dim sResult As String
    Dim sTempFolder As String

    'get the user's temp folder
    sTempFolder = GetTempDir()

    'create a dummy html file in the temp dir
    hFile = FreeFile
    Open sTempFolder & "dummy.html" For Output As #hFile
    Close #hFile

    'get the file path & name associated with the file
    sResult = Space$(MAX_PATH)
    dwFlagReturned = FindExecutable("dummy.html", sTempFolder, sResult)

    'clean up
    Kill sTempFolder & "dummy.html"

    'return result
    GetBrowserName = TrimNull(sResult)
End Function

Private Function TrimNull(Item As String)
    Dim pos As Integer
    pos = InStr(Item, Chr$(0))
    If pos Then
        TrimNull = Left$(Item, pos - 1)
    Else
        TrimNull = Item
    End If
End Function

Public Function GetTempDir() As String
    Dim nSize As Long
    Dim tmp As String
    tmp = Space$(MAX_PATH)
    nSize = Len(tmp)
    Call GetTempPath(nSize, tmp)
    GetTempDir = TrimNull(tmp)
End Function

'this is the cmdDefault_Click event function in another Form named
frmBrowserOptions
Sub cmdDefault_Click()
    ......................
    ......................
    ......................
End Sub

Assume that my browser is not the default browser. Now when I run the
browser from the IDE, the MsgBox asking the user whether he would like
to set my browser as the default browser or not comes up as expected
but when I compile the project into an EXE & then open my browser
(again assuming that my browser isn't the default browser), the MsgBox
comes up but immediately after that, VB generates the "Can't show
non-modal form when modal form is displayed" error.

Next irrespective of whether I click Yes or No in the MsgBox, the
following error gets generated:

An exception 'Unhandled Win32 Exception' has occured in MyBrowser.exe.
However, no debuggers are registered that can debug this exception.
Unable to JIT debug.

After this, the browser closes. My guess is that when the browser
loads, the other Form named frmBrowserOptions also Now how do I avoid
these 2 errors when I run the EXE? Please note that these 2 errors
don't get generated when I run the project from the VB IDE.

Thanks,

Arpan

4. Runtime error 401 - Can't show non modal form when modal form is displayed.

5. Non Modal Forms on Top of Modal One's

I wonder if there's any way around this.

I open a window as a modal form, but I would like to have pop up
message boxes appearing on top of this that are non modal (so the user
can close whichever of the pop ups they like). If I make the parent
window non modal this works fine.  I simply set the TopMost property
for each pop up so that is stays on top of the parent.  However as soon
as I make the parent window modal (which is absolutely essential in my
project) although the pop up windows appear you can no longer interact
with them.

Is there any way of getting this to work.  I hoped that setting parents
and owners would have an affect but so far nothing...

Thanks

6. Displaying a progress dialog - Modal / Non Modal error - Visual Basic/VB

7. Trying to Display a non-modal VB6 Form of an AcitveX DLL in C#

Hallo NG,

I'm trying to display a VB6 6 of an ActiveX DLL in c Sharp. I use 
therefore the SetParent API function. After this function call I get 
always the error message "Non-modal forms cannot be
displayed in this host application from an ActiveX DLL, ActiveX Control, 
or Property Page.". Does somebody know if it is possible to show a non 
modal Form, or has sombebody a workaround for that.

Thanks for your help.

Regards
Martin

8. Displaying a non-modal form - Visual Basic/VB