Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent opening multiple instances of VB application

My VB6 application is backed by a MS Access database. Allowing user to open multiple instances of the application would create conflicts & alter connected database.

Ideal solution would be to focus existing instance if user tries to open new one.

How can I attain this?

like image 839
Kushal Avatar asked Aug 12 '10 14:08

Kushal


1 Answers

Use App.PrevInstance:

'this code would be in a bas module for start up.'
Private Sub main()
    'Check for previous instance and exit if found.'

    Dim rc As Long

    If App.PrevInstance Then
        rc = MsgBox("Application is already running", vbCritical, App.Title)
        Exit Sub
    Else
        frmMain.Show
    End If

End Sub
like image 58
MusiGenesis Avatar answered Nov 04 '22 02:11

MusiGenesis