Solved

Load all forms, Second phase

Posted on 1998-09-16
13
181 Views
Last Modified: 2010-04-30
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.
0
Comment
Question by:DarkAge
  • 5
  • 4
  • 3
  • +1
13 Comments
 

Expert Comment

by:bennys
ID: 1435313
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
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1435314
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
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1435315
if you want a complete project (Load all forms)

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

enjoy.
0
 

Expert Comment

by:bennys
ID: 1435316
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
 

Expert Comment

by:kambhampati
ID: 1435317
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
 

Expert Comment

by:bennys
ID: 1435318
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 3

Expert Comment

by:a111a111a111
ID: 1435319
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
 
LVL 1

Author Comment

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

0
 
LVL 1

Author Comment

by:DarkAge
ID: 1435321
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
 
LVL 1

Author Comment

by:DarkAge
ID: 1435322
nd another note: Try it outside VB, Make an EXE and run the exe dont press F5 on vb
0
 

Expert Comment

by:bennys
ID: 1435323
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
 
LVL 1

Author Comment

by:DarkAge
ID: 1435324
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
 

Accepted Solution

by:
bennys earned 200 total points
ID: 1435325
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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now