Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Closing Form (VB6)

    I am using the following code to close a form, it does work but am not sure whether this is the correct.
    frmSplash loads then closes Form1024Image.
    Does my code look correct or is there a more correct way:

    <pre>Private Sub Form_Unload(Cancel As Integer)
    Set Form1024PDF = Nothing
    Unload Me
    frmSplash.Show
    End Sub</pre>


  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Closing Form (VB6)

    Which form is this code in?

    If it's in Form1024PDF, it would be more typical to destroy the object in the procedure that created it, rather than have an object try to destroy itself.

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Closing Form (VB6)

    Ok, here's how my application is set up:

    frmSplash (startObject)

    Form1024PDF
    Form1024JPG
    Form800PDF
    Form800JPG

    frmSplash is the opening form from which any of the other forms can be accessed (Depending on screen resolution).
    So on opening any of these other forms, what is the correct syntax to close frmSplash .

    The other forms when they close, need to return or .Show to frmSplash and unload themselves correctly.
    What would the syntax be for these.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Closing Form (VB6)

    I assume that you have command buttons or menu items on frmSplash to open the other forms. On Click code for these can look like:

    Private Sub cmd1024PDF_Click()
    Form1024PDF.Show
    Me.Hide
    End Sub

    Note that frmSplash ("Me") is not unloaded, only hidden, since the user will return to it later. In each of the called forms, you can put code in the On Unload event that shows frmSplash again:

    Private Sub Form_Unload(Cancel As Integer)
    frmSplash.Show
    End Sub

    Since frmSplash was still in memory, it only has to be made visible. If you like, you can put a "Close" command button or menu item on these forms.

    Private Sub cmdClose_Click()
    Unload Me
    End Sub

    Whether the user clicks this button, or the x in the upper right corner, or presses Alt+F4, the On Unload event will fire and show frmSplash.

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Closing Form (VB6)

    Thanks Hans
    I wasn't too sure what was still hanging around in memory once the application was closed.

Posting Permissions

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