Load all forms, Second phase

Well, i dont remamber how it was but to load all forms or load a form with it's name here is a simple progi (make sure you have tow forms, form1 unt form2):
Private Sub Command1_Click()
    Dim I As Form
   
    Set I = Forms.Add("form2")
    I.Show
End Sub
Just put a bottom on the first form for this code to run, and press F5, the progi runs and when you press the button on form1 the second form is opend, this is nice and since I have the DB file will all forms name i can easly load any form if i know it's name (I have about 70 forms to load when i user request to),Okay now make an EXE of it and press the button - BEEEEEEEEEEEP - Automation error!!!!
Jesus, It works on VB mode but on EXE it dos'nt!!! Hey you that answered my Question before, give me back my points or help me out here!!! You gave me half answer!!!
Thanks.
LVL 1
DarkAgeAsked:
Who is Participating?
 
bennysConnect With a Mentor Commented:
the error you got is right , but has nothing to do with the loading problem. the forms you are tring to load must all be set in design time to be "MDIChild --> TRUE" , otherwise they can't be loaded into a MDI window. i have written another sample , this one loads a child window in an MDI form.
to use the sample :
create a new project , mdiform and a regular form.
set the regular form's MDIChild property to "TRUE".
create a module.
put this code in the module :

Sub main()
Dim f As Form
Set f = Forms.Add("mdiform1")
f.Show
End Sub

put this code in the MDI form :

Private Sub MDIForm_Click()
Dim f As Form
Set f = Forms.Add("Form2")
f.Show
End Sub

i used the click event , but you can use any other event.
this code loads the MDI form , and when you click the form it loads form2 into the MDI form , as a child.

have fun.

Benny

0
 
bennysCommented:
Hello DarkAge.
there are two ways to load a form:
1. call "Load FormName"
2. use "Forms.Add"
you can't mix the two methods , as you saw.
if you want to use "Forms.Add" , you must load the first form and all others through that method. create a sub main , and load the first form using Forms.Add
Good Luck.
\\Benny
0
 
a111a111a111Commented:
I was late after bennys by 2 minute!

I guess that array of forms can be helpful but in any case I have a small code for you :


Private Sub Form_Load()
Form2.Show
Form3.Show
Form4.Show
Cascade Form1 'you may take it out
Cascade Form2 'you may take it out
Cascade Form3 'you may take it out
Cascade Form4 'you may take it out
End Sub
Sub Cascade(TheForm As Form)
    Static TopX, TopY As Integer
    TheForm.Width = Screen.Width / 4
    TheForm.Height = Screen.Height / 4
    TheForm.Move TopX, TopY
    TopX = TopX + Screen.Width / 10
    TopY = TopY + Screen.Height / 10
End Sub


or:

sub command1_click ()
Form2.Show
Form3.Show
Form4.Show
end sub



0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
a111a111a111Commented:
if you want a complete project (Load all forms)

get it at http://www.hili.com/~shay/allforms.zip

enjoy.
0
 
bennysCommented:
sorry A111 , didn't mean to play dirty (if that's what i did.)
is there any ethical code that we all obey to here ?
0
 
kambhampatiCommented:
hello darkage,
below code  will solve your problem

     Private Sub Command1_Click()
          dim i as form
          Dim I As new Form2
       
'       Set I = Forms.Add("form2")
          I.Show
   End Sub

regards


anji
0
 
bennysCommented:
anji , this is good in the example code but as i understood from DarkAge's question he wants to use this method to load forms by their name which is taken from a database table. in that case he will not know the form name at design time.
0
 
a111a111a111Commented:
bennys:
Forget about it.
The only thing that got me is EE hangs for about 3 minute before
is finish the process.

That's all.
0
 
DarkAgeAuthor Commented:
Well, Benny, Can you give me an example code? Becuase I dont understand what the heck r u talking about!

0
 
DarkAgeAuthor Commented:
Okay, Here is some clearens of what is the progi al about:
I have a databse file (MDB) with form names, The user see the lists of the forms select one and pop! the form appear on the screen, selectiing a nother form will unload the the current form and will display the new form.
I'm willing to get answers only if you can supplay with a code sample (I dont need the whole mechanisim, Just how to load a form whaich i dont know it's name at design time) and it should run outside VB.

0
 
DarkAgeAuthor Commented:
nd another note: Try it outside VB, Make an EXE and run the exe dont press F5 on vb
0
 
bennysCommented:
OK. here it goes.
to use the sample code , create a new project,
two forms named form1 and form2 , a command button on form1,
and a module to hold the sub Main().
set the project startup to the sub main (!!) , not form1.
THE MODULE CODE:
Sub main()
Dim f As Form
Set f = Forms.Add("form1")
f.Show
End Sub

FORM1 CODE:
Private Sub Command1_Click()
Dim f As Form
Set f = Forms.Add("Form2")
f.Show
End Sub

why is that working ?
vb has a bug that says that all form must be loaded in your program in the same manner.
when you set a startup form , vb uses "Load" function to load that form. if later on you try to use "Forms.Add" you get that automation error. to avoid that you set the project startup to your sub Main() , and use that sub to load the first form with the "Forms.Add" method.

if you need more info about that , let me know.

0
 
DarkAgeAuthor Commented:
Well boys and girls look like when I used this methode to open the start up forms, Every time on the code when I Try to access the windows I have opned with this kind of methode (Forms.Add) i get thier could be only one MDI form.
PS: The main form is an MDI window, If i didnt menthion that here it is now.
If any body want't the code to view on it just ask me at darkage@isdn.net.il
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.