开发者

Prevent opening multiple instances of VB application

开发者 https://www.devze.com 2023-01-11 01:54 出处:网络
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.

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?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消