Results 1 to 8 of 8

Thread: how can i call form_load on form1 from form2 ?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Bergen, Norway
    Posts
    143

    Question

    Greetings,

    How can i call form_load that is located in form1 from form2 ?

    Thanks in advance.


    -Lumin

  2. #2
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Load frmForm1

    I am not sure exactly what you want to do.

    To load a form, just do "Load frmForm1", where "frmForm1" is the name of the form you want loaded. This will not show the form. In the Form_Load subroutine, to actually show the form do "frmForm1.Show".

    I do not think you can execute the Form_Load subroutine for frmForm1 from some other form. If you did, there might be a lot of statements which would not work anyway.

    If there is code you want executed when frmForm1 loads, and also want the same code executed when frmForm2 is active, you could put the common code in a Public subroutine in a Code Module. Then call the public subroutine from the frmForm1 load_form subroutine and also call it from code used by frmForm2.

    I hope the above helps. If not, post further questions in this Thread.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  3. #3
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    I don't think you can actually call the Load event manually, but it does get called when the form is first loaded. If you load Form1 from Form2, Form1's Load event will be activated.
    Code:
    'a sample command button in Form2
    Private Sub cmdLoadForm1_Click()
    
       Load Form1
    
    End Sub
    
    'inside Form1
    Private Sub Form_Load()
    
       MsgBox "Form1 just got loaded", vbOKOnly, "Notice"
    
    End Sub
    So if you use this, and press the command button, Form1 will be loaded, and when the load event of it is triggered, the message box will appear.


    [Edited by Kaverin on 10-18-2000 at 08:46 PM]
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Bergen, Norway
    Posts
    143
    thanks.

    but form1 is already loaded.. and I need to reload the form_load sub

    is there any other way to do this?


    -Lumin

  5. #5
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Hi,
    Why not put all the code in Form_Load of Form1 in a function and call this function from Form2 when u need it.

    eg.
    Code:
    'Form1 code
    Private Sub Form_Load()
    Call myInit
    End Sub
    
    
    Public Function myInit()
        'your code
    End Function
    
    'Form2 code
    
    Private Sub Command1_Click()
    Call Form1.myInit
    End Sub
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  6. #6
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Another thot.

    Perhaps you should take some of the code out of your Form_Load subroutine and put it into Form_activate or Form_Got_focus subroutine.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  7. #7
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524
    Just use form_activate()
    u can reload the code u want to use when the form is active.

    Cheers,
    Wen Lie
    Regards,
    [-w-]

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Bergen, Norway
    Posts
    143
    hehehe.. I just realized that I had made this problem much bigger then it originaly was.. I don't know why i didn't think about public functions before..

    oh well a reminder is always handy

    Thanks a lot for all the Help evryone!!


    -Lumin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width