Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Modal Form

Posted on 1999-07-01
Medium Priority
Last Modified: 2010-05-02
I have a single Form (a simple one, just a message and an OK button to Unload and End) that I wish to display in Modal style.  I could not find a Property for this, so I created a Sub Main Module as the startup and put in the following: vbModal

But this does not work.  When I click outside the Form, it minimizes to Task Bar.

How do I create a single Modal Form?
Question by:jalymo
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Expert Comment

ID: 1521360
if it's just a messege and an ok button, why don't you call a system modal msgbox from the form, and set the form.visible to false

Accepted Solution

clifABB earned 120 total points
ID: 1521361
I am unable to duplicate this problem.
What I did so was run it and click on the VB IDE which came to the front hiding the form (but it did not minimize).  Is this possibly what happened?  Try minimizing the VB IDE and see if the form is underneath.

If this is what happens, this is the way vbModal does work.  I believe what you are trying to accomplish is to keep the form on top of all other windows.  You can do this with this code:

In the declarations section of a module paste this code:
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Const HWND_TOP = 0
Public Const HWND_BOTTOM = 1
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_SHOWWINDOW = &H40

Use This code to show your form:
Call SetWindowPos(Form1.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE + SWP_SHOWWINDOW)


Author Comment

ID: 1521362
clifABB --

Look's good!!  Before I give you your points, could you answer a couple more questions --  This Form will be a logon message that will be initiated by our Network logon script and seen by hundreds of machines, from some 486s to P300s.  I'm going to do a "make .exe" and have the network guy execute it from his batch script.  

Do you see any problems with this program running on different machines?  Can the .bat file run my .exe?


Expert Comment

ID: 1521363
"Do you see any problems with this program running on different machines?"
No, as long as they are all Intel machines this should be ok.
"Can the .bat file run my .exe?"
Yes, from Win95 and up and WinNT 4.0 and up.

Author Comment

ID: 1521364

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question