Losing focus on forms

I have a program that has multiple forms open at the same time. However, only one is ever enabled at one time. When the second form loads, it disables the first form. When the third form loads it disables the second. Only the main form is shown in the taskbar.

When I switch to another program and then come back, the focus is not on the topmost form. I regain the focus by simply clicking on the form but this can be annoying as I switch between programs regularly.

In short the question is "How can I keep the focus where I left off, even if a different form is shown in the taskbar?"

Thanks in advance!

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

There is an property of the form
which is showupintaskbar or something
enable that. That should solve your problem
melvynmyersAuthor Commented:
I don't want every form to show in the taskbar - only the main form.


Do you ever need to get back to the main form or just the current one? If you don't need to get back to the main form, maybe you could open the form modally (form2.show vbModal). No matter what you can only goto that one form. Or you could possibly use a form2.setFocus whenever the main form was activated.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

melvynmyersAuthor Commented:

That did the trick! Thanks a whole heap!!

Please post an answer so I can transfer the points.

Can I also ask, what does vbModal do??


vbModal is a state that a form can take. It means that until you do something to that form, the user can't continue in the project. One example of a "form" that is modal is a message box. (I know that a message box isn't necessarily it's own form...) When you put a Message Box in the form, such as this -
MsgBox "I'm a message box"

the program will have the message box on the form until the user does something to get rid of the message box. In this case, since I didn't specify what type of message box I want, the defualt is just an "OK"-button (vbOkayonly). When the OK button is pressed, the user can continue using the program.

One type of forms that is usually modally loaded is an About Box Dialog form, which is just a form template you can add to your project.

Understand that weird programming junk? :) I hope it helped.
melvynmyersAuthor Commented:
Thanks everyone for your help, including the_next_jimi for your great explanation of modal forms!

I would like to give points to everyone but as ggilman provided the original solution I will have to give the points to him.


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.