finding a running instance of a form in

Posted on 2004-10-26
Last Modified: 2012-05-05
  I want to know how i can find an running instance of a form so that i can restrict the user to reopen the same form again.
 Say as a address book is open using this code lines.......

  Dim addbook_new As New frmAddressBook()

if the user again clicks address book link , and if the address book already open , then restrict the user to reopen it. all i want is to find an running instance of an form...

I don't want to use a variable for decision.....

Please reply.....


Question by:manish_prajapati
    LVL 8

    Expert Comment

    Can't you just use the visible property of the form to identify if it's visible?

    If frmAddBook.visble then exit sub ...
    LVL 76

    Expert Comment

    There is a VB.Net area. The answers you get here are likely to be biased towards non-.Net visual basic.
    LVL 26

    Expert Comment


    Author Comment

    Hi, There is problem in it.. I am explaining you..

    Suppose i take a global declaration as
       dim frmaddbook as new frmaddressbook()

    and on clicking address book Icon , i show the form by

    when user again clicks the ICON ,I check if frmaddbook.visible=ture and if ture then EXIT SUB.
    if user closes the address book form and after then clicks the address book gives a fault that .. frmaddbook instance is diaposed and it couldn't be shown bt .show

    I need to find the instance of frmaddbook so that i can check the status whether it is open ,closed....\

    LVL 85

    Accepted Solution

    You can do it using a technique similar to this:

    Public Class Form1
        Inherits System.Windows.Forms.Form

        Private WithEvents frmAB As frmAddBook

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If frmAB Is Nothing Then
                frmAB = New frmAddBook
            ElseIf frmAB.WindowState = FormWindowState.Minimized Then
                frmAB.WindowState = FormWindowState.Normal
            End If
        End Sub

        Private Sub frmAB_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles frmAB.Closed
            frmAB = Nothing
        End Sub

    End Class


    Author Comment

    Thanks, It is working


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT Security CISA, CISSP & CISM Certification

    Master the advanced techniques required to protect network resources from external threats with the IT Cyber Security bundle. Built around industry best-practice guidelines, the IT Cyber Security bundle consists of three in-depth courses.

    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    933 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now