I just found this other solution that is a tad more involved but will allow you to actually switch over to the running instance (Win95 and NT4 only -- will not work for Win98):<br>
<br>
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long<br>
<br>
Public Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Long<br>
<br>
Private Sub Form_Load()<br>
<br>
Dim hdl As Long<br>
Dim rc As Long<br>
<br>
hdl = FindWindow(vbNullString, "The Real Caption"

<br>
If hdl > 0 Then<br>
rc = SetForegroundWindow(hdl)<br>
End<br>
Else<br>
Me.Caption = "The Real Caption"<br>
End If<br>
<br>
End Sub<br>
<br>
Here's how it works (there's a trick described later):<br>
<br>
The FindWindow API requires exact description of the Window you're trying to find. The API returns a handle to the Instance that's running. If the handle is 0 then there is no other instance; otherwise, we feed the handle to the SetForegroundWindow API to make that instance the front app.<br>
<br>
The trick is this: as mentioned in the original post, as soon as the application starts, the FindWindow will a return a reference to itself (the new instance). This means that we would really never know whether or not there is another instance. So here's what we do:<br>
<br>
At design time, change the caption of the main form to some "dummy" text. When the application starts, use the "real" caption as the parameter in the FindWindow API. If the API returns non-zero then switch to the app; otherwise, change the caption of the form to the "real" text and continue on with the app.<br>
<br>
It seems complicated but it is real simple and works well (on Win/95 and Win/NT only). Win98 and Win2000 do not allow you to change the focus to another application -- or something like that (do not quote me on this one)<br>
<br>
Remember, if you don't need to switch over to the running instance then use Mike's code above -- it's simple and very effective.<br>
<br>
Tarek