-
I've made an app with lot of forms. When I go from one form to another. I make this:
-------------
Load Form1
Form1.show vbmodal
-------------
Making this I go from form1 to form2.
My problem is that in my app I should be able to go from any form to any other form. Then, it's possible that when I go from form1 to form2, form2 can be loaded and visible, yet. I have a run-time error:
----------------
Run-time error: 400
The form is already visible. It can't be loaded in modal way
---------------
How can I validate if form2 is already loaded?. Which is teh best way to go from one form to other?.
Any solutions will be gretaly apreciatted.
Nauj
-
Do you need to open each form as Modal??
You would probably get away with implementing this code.
Code:
'Show the appropriate form
Form2.Show
'Hide the current form
Me.Hide
If the specified form isn't loaded when the Show method is invoked, Visual Basic automatically loads it.
-
If the forms don't truly need to be modal and you have a number of forms, you may want to consider using MDI and making each form a MDI child. Then you can have 1 menu and/or toolbar drive the rest of your app.
-
is there any way to make a MDI child form MODAL? or act like modal?
-
disable all other mdi childs
-
Two things that I have used.
One is to have each form set a state, the value of the state is passed to a routine which handles showing the form. In this case, every line of the sort Form.show is in one single SUB, and therefore, the state of the form can be maintained. Each place where you have Form.show, you can replace it with a call to the routine that shows the form, and it can take appropriate action.
A problem with showing a form from another form which can show the first form, etc. Is that each Form.show vbModal means that the current routine is halted while execution is transferred to the newly shown form. Each such action uses some stack space. If you can have form1 show Form2 modally, and form2 then show form 1 modally, you can exhaust the stack and crash the computer.
Having a central dispatch for showing forms can remove that problem since each form can be hidden from a central location.
A second thing I have done is to make an array of forms. Keep track of the last one shown, and show the next one next time. That doesn't seem to be what you are trying to do, but I could be wrong.
A third idea is to maintain a global array for the state of the forms. This can be simply boolean. During the Load event for each form, set the array slot for that form to True. During the Unload Event, set the array slot to False. Then you can check the status of the form before showing it.
-
Well
You could try to use SetTopWindow API call...