×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Disallowing Multiple Instances Of VB Project

Disallowing Multiple Instances Of VB Project

Disallowing Multiple Instances Of VB Project

(OP)
Hello --

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???

RE: Disallowing Multiple Instances Of VB Project

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.

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 !

If App.PrevInstance Then
MsgBox ("Cannot load program again."), _
vbExclamation, "The requested _
application is already open"
Unload Me
End If

Jim jdmcjen@stc.net

RE: Disallowing Multiple Instances Of VB Project

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.

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Sub CheckInstance(strTitle as String)

Dim lApp As Long
Dim intShown As Integer

'Check for a duplicate instance of the program.
lApp = FindWindow(vbNullString, strTitle)

'If lApp is something other than 0, then there is a current instance running.
If lApp <> 0 Then
If SetForegroundWindow(lApp) Then
intShown = ShowWindow(lApp, 1)
End If
End If
End Sub

You call it from your program, by passing the information on the caption of the form.

CheckInstance "Insuarance Claims Processing Module"

Be sure the caption of your form has the same spelling as what you use in the call to CheckInstance.

Steve
sdmeier@jcn1.com

RE: Disallowing Multiple Instances Of VB Project

Also, Edderic posted a very handy method for identifying all running apps. You can find it in the VB 5&6 thread marked "Unauthorized Applications" (2/3).

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close