Link to home
Start Free TrialLog in
Avatar of MOvais_Khan
MOvais_Khan

asked on

Multiple Instances of an application


Dear Experts,

How can we prevent a VB program from running multiple instance of it. As some users intentionally try to open multiple instance the program.

Rgds/Shihab
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JigglyD
JigglyD

Try This...

Sub Main()
      If App.PrevInstance Then
         MsgBox "An instance of this program is already running...", vbInformation, ""
         Unload Me
      Else
         frmMain.Show  '*** Assuming that frmMain is your current Startup form
      End If
End Sub

Jiggle On ! ! !
GIVE ME NO POINTS FOR THIS------------------------

because JigglyD wrote the same code (almost)

If u want just to unload the new instance, with no messages, etc, just write:

If app.previnstance then end

inside the Sub Main()