Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disallowing Multiple Instances Of VB Project

Status
Not open for further replies.

Gettoblaster

Programmer
Feb 4, 2000
13
0
0
GB
Hello -- <br>
<br>
I have tried the app.previnstance in order to end the project (if there is one already open) but the problem is that the app.previnstance always = false no matter how many instances of the project i have open. I use the app.previnstance command in the mainmodule sub main. does anybody have any ideas???
 
Nothing specific, unless the version of VB you are running needs to be wiped from your hard drive and reloaded. Sounds funny I know, but on several occasions recently I have had VB doing things it shouldn't or NOT doing things it should and a simple reload cleared up the problems. Not all of the problems, but most.<br>
<br>
I was looking through my code library and found the following source sample but you said it isn't working for you .... so I am at a loss ! <br>
<br>
If App.PrevInstance Then<br>
MsgBox (&quot;Cannot load program again.&quot;), _<br>
vbExclamation, &quot;The requested _<br>
application is already open&quot;<br>
Unload Me<br>
End If<br>
<br>
Jim <A HREF="mailto:jdmcjen@stc.net">jdmcjen@stc.net</A>
 
This was posted some time back, I don't remember by who, but here's the information you need. This is not the one that was posted but one we have been using for about 2 years now.<br>
<br>
Declare Function FindWindow Lib &quot;user32&quot; Alias &quot;FindWindowA&quot; (ByVal lpClassName As String, ByVal lpWindowName As String) As Long<br>
Declare Function SetForegroundWindow Lib &quot;user32&quot; (ByVal hwnd As Long) As Long<br>
Declare Function ShowWindow Lib &quot;user32&quot; (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long<br>
<br>
Sub CheckInstance(strTitle as String)<br>
<br>
Dim lApp As Long<br>
Dim intShown As Integer<br>
<br>
'Check for a duplicate instance of the program.<br>
lApp = FindWindow(vbNullString, strTitle)<br>
<br>
'If lApp is something other than 0, then there is a current instance running.<br>
If lApp &lt;&gt; 0 Then<br>
If SetForegroundWindow(lApp) Then<br>
intShown = ShowWindow(lApp, 1)<br>
End If<br>
End If<br>
End Sub<br>
<br>
You call it from your program, by passing the information on the caption of the form.<br>
<br>
CheckInstance &quot;Insuarance Claims Processing Module&quot;<br>
<br>
Be sure the caption of your form has the same spelling as what you use in the call to CheckInstance.<br>
<br>
Steve<br>
<A HREF="mailto:sdmeier@jcn1.com">sdmeier@jcn1.com</A>
 
Also, Edderic posted a very handy method for identifying all running apps. You can find it in the VB 5&6 thread marked &quot;Unauthorized Applications&quot; (2/3).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top