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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop Multiple instances 1

Status
Not open for further replies.

fortage

MIS
Jun 15, 2000
329
US
I have a VB 6 app running on NT4 or 2000 and wnat to stop users from start it multiple times simultaneously. Do I need to check if the process is running? The only way I can think is shelling to DOS and using NT command line utilities. There must be a better way. How?
 

something like...

---------------------------------------------------------
Private Sub Form_Load()
If App.PrevInstance Then
MsgBox ("Application already open."),vbExclamation, "Application already open."
Unload Me
End If
End Sub
---------------------------------------------------------

Sunaj
 
Code:
Dim savetitle
    
    If App.PrevInstance Then
       savetitle = App.Title
       App.Title = "... duplicate instance."
       form1.Caption = "... duplicate instance."
       AppActivate savetitle
       SendKeys "% R", True
       End
    End If

put it in the main form load.. winn end program and highlight the first instans ..

/ola
 
I know this is an old thread, but I'm sort of having the same problem but with Access. I have a form set up where a user can select criteria and then hit a button and create labels/envelopes/letters via a mail merge with Word. Whenever the application merges to Word, a new instance of Access is opened. I'm trying to write something like what you have above, but I'm not that fluent with VBA.

On my main, startup form, I have the following:

Private Sub Form_Load()
Dim App as Access.Application
If App.previnstance Then
Unload Me
End if
End Sub

But the code doesn't seem to be working. Do I need to have a line in there that says: Set App = GetObject (,"Access.Application") ? Can someone please help me? Thanks!
 
I'm not very fluent with Access coding, as it is different from VB, but I do know that App is a Visual Basic keyword that refers to your application. You may try renaming that variable to something like AccsApp, or remove the line "Dim App as Access.Application" altogether. Also, if Access will let you make Sub Main as the startup object instead of a form, then this is the most effective place to detect for a previous instance (I learned that the hard way making a screen saver, Windows launches several instances of screensavers for some reason ;-)

Another thing you might try if Sub Main isn't an option is to unload all forms using this loop:

Do While Forms.Count > 1
Unload Forms(1)
Loop

Note that this loop unloads all forms except the form where the loop resides. For that reason, you'll still need to include the Unload Me statement after it.

Hope that gives u some ideas!

-Mike

Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top