Results 1 to 6 of 6

Thread: load form

  1. #1

    Thread Starter
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946
    I open form1 (nag), run it's code, and then
    I want to unload it and load the main form.
    How do I load form2
    if I try this
    unload form1
    load form2
    it doesn't work
    I know of visible and invisible but that doesn't instigate the form load event..

    how can I open form2 and run the form load
    or do I have to use the visible and invisible and then call the form load event after it is visible.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  2. #2
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Originally posted by HeSaidJoe
    I open form1 (nag), run it's code, and then
    I want to unload it and load the main form.
    How do I load form2
    if I try this
    unload form1
    load form2
    it doesn't work
    I know of visible and invisible but that doesn't instigate the form load event..

    how can I open form2 and run the form load
    or do I have to use the visible and invisible and then call the form load event after it is visible.
    Just put the form2.Show after the load form2 command.

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Your code does run the Form2 Load event, it just doesn't show Form2. Add Form2.Show or Form2.Show vbModal following the load, or just replace the load statement with the show statement since it will cause both to happen.

  4. #4
    Member
    Join Date
    Jun 2000
    Location
    Dallas, Texas
    Posts
    52

    My 2 cents

    I was having the same problem, being very new at this, what worked for me was this:

    Form1.Show
    Form2.Hide

    and the reverse when I wanted to go back to the original form.

    Hope this helps, it sure worked for me..... Jim

    PS... I attached this code to command buttons.

  5. #5
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Re: My 2 cents

    Originally posted by Necromancer
    I was having the same problem, being very new at this, what worked for me was this:

    Form1.Show
    Form2.Hide

    and the reverse when I wanted to go back to the original form.

    Hope this helps, it sure worked for me..... Jim

    PS... I attached this code to command buttons.
    Do you mean to hide the Form2 and put the Form1 back to the screen?

    Assume Form1 is your startup form.
    Code:
    Option Explicit
    'For the second solution
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As String) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Const SW_SHOWNORMAL = 1
    Private MyForm1Caption As String 
    
    Private Sub Form_Load()
       MyForm1Caption = Form1.Caption
       Me.hide
       Load Form2
       Form2.Show vbModal
       'Or
       Form2.Show
    End Sub
    
    Private Command1_Click()
       Form2.hide
       Form1.Show
    
       'Or you can you the FindWindow API to serach for the Form1 and use the ShowWindow API to Display the Form1 on the screen.
        Dim xhwnd As Long
        xhwnd = FindWindow(0&, MyForm1Caption)
        If xhwnd <> 0 Then
            ShowWindow xhwnd, SW_SHOWNORMAL
        Else
            Load Form1
            Form1.Show vbModal
        End if
    End Sub
    Hope this will help you.

    [Edited by Chris on 06-18-2000 at 08:07 PM]

  6. #6

    Thread Starter
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    thanks.

    should have posted this earlier..
    the Form2.show works fine for my purpose

    Thanks all...
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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