Results 1 to 4 of 4

Thread: [RESOLVED] Form Assistance

  1. #1

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    32

    Resolved [RESOLVED] Form Assistance

    My project uses 5 forms and 3 of these forms need to be accessible to other forms. I have declared these forms as Public in a Code Module and am able to successfully access the properties and controls on the form.

    When the app is first loaded, none of these forms are visible. When a user requires the form they simply click on a button and the form appears. After the user is done with the task on the "accesible form" my code hides the form.

    The issue that I have is if I simply hide the form the values still exist and if I close the form I'm no longer able to open.

    My resolution is to call a sub that clears all the controls and variables associated with these 3 forms.

    My question is if there is a better way of clearing the form, so that I can simply do form.close and when the user needs the form it can reopen.

  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 Assistance

    You could just do the .Close to destroy the form and clear everything. Then when you need it again you can re-instanciate it. This kind of defeats the need for it being public but it still depends on your app.

    Instead of a .Show call you could call a custom procedure to clear and show so you dont have to remember to clear the form.
    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
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Form Assistance

    In your module you can use something like this:
    VB Code:
    1. Public myForm1 As Form1
    2.  
    3. Public Sub ShowForm1()
    4.     If myForm1 Is Nothing OrElse myForm1.IsDisposed Then
    5.         myForm1 = New Form1
    6.         myForm1.Show()
    7.     Else
    8.         myForm1.Activate()
    9.     End If
    10. End Sub
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    32

    Re: [RESOLVED] Form Assistance

    I appreciate the assistance. I have been struggling with that for the past 5 days. Now I can rest soundly


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