Results 1 to 3 of 3

Thread: Form close and re-show problems.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    124

    Form close and re-show problems.

    Ok, I cannot open a particular form after it has already been loaded.

    frmQ1.Show()
    Me.Close

    This is the code i use to close Q1. Then whe I try to re-show it again from frmMenu I get an error saying it cannot load the disposed object. What does that mean? I guess that it is because I closed it instead of hiding it. But when I hide it, I want it to activate the Form Load event again which I can't really do unlees I restart the form and I don't know how to do it. Any help appreciated.
    I never know what to put in this section...



    So sue me... ... ... I'm just kidding...


    www.fat-pie.com Flash Movies... You gotta see 'em to believe 'em!

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Form close and re-show problems.

    Two things. One, when you defined the form frmQ1 you probably instanciated it with something like
    "Public frmQ1 As New frmQ". When you .Dispose of the form by way of the .Close method, your
    destroying the instance of frmQ1.

    To fix that, yes, you just do a .Hide/.Show or create a new instance of it when you need to show it again, like I just coded.
    This will take care of #2 but if your always destroying/creating the same form then its better on resources and performance if you .Hide/.Show.

    Now this brings up issue #2 again. To get around that, you need to re-code the load event so things happen differently
    rather then relying on the load event.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    New Member
    Join Date
    May 2005
    Posts
    11

    Re: Form close and re-show problems.

    Hi martw,

    Whenever I open a form in a project, I use the following approach:

    In this example, the name of my form is Window

    VB Code:
    1. ' First declare the object
    2. Dim objWindow as New Window
    3.  
    4. ' Now insert the following after an event to open the form
    5.  
    6.         If Not objWindow Is Nothing Then
    7.             If objWindow.Created = True Then
    8.                 objWindow.Show()
    9.                 objWindow.Activate()
    10.             Else
    11.                 objWindow = New Window
    12.                 objWindow.Show()
    13.                 objWindow.Activate()
    14.             End If
    15.         End If

    With this code, you can close forms or hide them; either way thay should open correctly.

    NPath

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