Preventing multiple instances of a VB application from opening

I am working on a VB6 application that is associated with an MS Access database, so I do not want to allow the user to open multiple instances of my application, as this will create conflicts and modify the associated database. In addition, if the user tries to open another instance, the current executable instance must be focused. How can I achieve this? Thanks in advance..........: -)

+5
source share
1 answer

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
+6
source

All Articles