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!

Mel
LVL 1
melvynmyersAsked:
Who is Participating?
 
ggilmanConnect With a Mentor Commented:
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.
0
 
garbage76Commented:
There is an property of the form
which is showupintaskbar or something
enable that. That should solve your problem
0
 
melvynmyersAuthor Commented:
I don't want every form to show in the taskbar - only the main form.

Cheers!

Mel
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
melvynmyersAuthor Commented:
ggilman,

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??


Cheers,

Mel
0
 
the_next_jimiCommented:
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.
0
 
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.

Cheers!

Mel
0
All Courses

From novice to tech pro — start learning today.