How to determine whether there’s another (compiled) instance of the application running in the system
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 'System & API - How to determine whether there's another (compiled) instance of the application running in the system 'The PrevInstance property lets you determine whether there's another '(compiled) instance of the application running in the system. This can 'be useful if you want to prevent the user from accidentally running two 'instances of your program: Private Sub Form_Load() If App.PrevInstance Then ' Another instance of this application is running. Dim saveCaption As String saveCaption = Caption ' Modify this form's caption so that it isn't traced by ' the AppActivate command. Caption = Caption & Space$(5) On Error Resume Next AppActivate saveCaption ' Restore the Caption, in case AppActivate failed. Caption = saveCaption If Err = 0 Then Unload Me End If End Sub |