问题
I'm working on VB6 application, which is connected to MS Access database, so I don't want to allow user to open multiple instances of my application as this will create conflicts & alter connected database. Also, if user tries to open another instance, the currently running instance must be focused. How can I attain this? Thanks in advance.......... :-)
回答1:
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
来源:https://stackoverflow.com/questions/3468616/prevent-opening-multiple-instance-of-vb-application