Link to home
Start Free TrialLog in
Avatar of DarkAge
DarkAge

asked on

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.
Avatar of bennys
bennys

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



if you want a complete project (Load all forms)

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

enjoy.
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 ?
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
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.
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.
Avatar of DarkAge

ASKER

Well, Benny, Can you give me an example code? Becuase I dont understand what the heck r u talking about!

Avatar of DarkAge

ASKER

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.

Avatar of DarkAge

ASKER

nd another note: Try it outside VB, Make an EXE and run the exe dont press F5 on vb
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.

Avatar of DarkAge

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of bennys
bennys

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial