A simple solution is to change your own form's caption to some other value before calling AppActivate so that AppActivate does not try to activate your own program.
___
[tt]
Private Sub Form_Load()
If App.PrevInstance Then
Dim S As String
S = Caption
Caption = "Something else..."
AppActivate S
Unload Me
Else
'start program normally
End If
End Sub[/tt]
___
This code works fine... but still has a small problem.
If the previous instance of the program is minimized, AppActivate is not able to restore that minimized window, although the window is activated on the taskbar!
To work around this problem, here is some API based solution which does the trick neatly.
___
[tt]
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function OpenIcon Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Form_Load()
If App.PrevInstance Then
Dim S As String, H As Long
S = Caption
Caption = "Something else..."
H = FindWindow(vbNullString, S)
If IsIconic(H) Then OpenIcon H
SetForegroundWindow H
Unload Me
Else
'start program normally
End If
End Sub[/tt]