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

how to stop multiples of the same application from running

Status
Not open for further replies.

johnnyplang

Programmer
Apr 26, 2006
9
US
I have an application that opens in VB but when then action is triggered again another instance of the program opens instead of maximizing the first instance. I tried the below but that doesn't work.

hwnd = FindWindow(vbNullString, "program X")
If hwnd <> 0 Then
AppActivate "program X"
Else
Shell ("c:\Program X.exe")
End If
 
GD,

What is App.PrevInstance? I get an error when it gets to that step. Sorry for being a rookie.
 
guitardave78,

Did you look at the site I posted the link for? Your solution doesn't bring the 'Previous Instance' to the front.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
guitardave78,

It faulted on the App.PrevInstance line. I am not sure what that does?
 
if you are on the main form (the one that loads up at the start of the app) and you type app. you will get a list of methods etc, one is PrevInstance. All it does is look to see if it is already running. If it is it unlods the main form...thus closing the application.

}...the bane of my life!
 
App" is the Application object and it is a builtin object in every VB application. It provides you with information about the current application. For example
[tt]
App.PrevInstance --> TRUE if another instance is running
App.Path --> The path to the .VBP or .EXE file
App.EXEName --> The name of the EXE
etc.
[/tt]

[small]No! No! You're not thinking ... you're only being logical.
- Neils Bohr[/small]
 
What version of VB are you using?

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
It is VBA. Its part of an operator interface software package. Normally we don't have to go to this level so again pardon my inexperience. There are no app.* that are listed.

johnny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top