views:

51

answers:

1

Hi everyone,

I'm working on VB6 application, which is connected to MS Access database, so I don't want to allow user to open multiple instances of my application as this will create conflicts & alter connected database. Also, if user tries to open another instance, the currently running instance must be focused. How can I attain this? Thanks in advance.......... :-)

+3  A: 

Use App.PrevInstance:

'this code would be in a bas module for start up.'
Private Sub main()
    'Check for previous instance and exit if found.'

    Dim rc As Long

    If App.PrevInstance Then
        rc = MsgBox("Application is already running", vbCritical, App.Title)
        Exit Sub
    Else
        frmMain.Show
    End If

End Sub
MusiGenesis
Thanks, that worked perfectly, now is there anyway to set focus to current instance instead of showing error message..?
Kush
Yeah, use the `AppActivate` method - pass in whatever's in the title bar of your application.
MusiGenesis