You can try something like this,
Code:Option Explicit Dim terminate_app As Boolean Private Sub Form_Load() If App.PrevInstance Then terminate_app = True MsgBox "A copy of My Program is already loaded!", vbInformation Unload Me Exit Sub End If ' YOUR CODE HERE End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If terminate_app = True Then Exit Sub ' only run on normal exit ' Stop timers, close open files, save user settings, etc,etc, End Sub Private Sub Form_Unload(Cancel As Integer) Dim i As Integer ' unload forms For i = Forms.Count - 1 To 0 Step -1 Unload Forms(i) Next i 'Set Form1 = Nothing End Sub




Reply With Quote