Solved Focus opened instance when luser tries to open a second instance (1 Viewer)

Fernando

Registered User.
Local time
Today, 11:57
Joined
Feb 9, 2007
Messages
89
Hello access gods,
I have successfully implemented the code to prevent multiple instances from this article found in this forums : http://www.mvps.org/access/api/api0041.htm
Now, can someone please enlighten my path on how to automatically focus on the original instance after preventing the user to open a new one?. Thanks in advance.
 

Steve R.

Retired
Local time
Today, 11:57
Joined
Jul 5, 2006
Messages
4,707
I have never used this procedure. But in reading the directions at the MVPS website and if I understand your question correctly, the implication is that you would only have one database open so there would be no necessity to "focus on the original instance"

"It checks each other instance of Access currently running and if the titlebar of the ODb class window matches the active instance then it activates the other instance and terminates the current one. "

Now if you want the focus to be on a specific control, you could use the FormActivate or FormOpen event to run either DoCmd.GoToControl or ControName.SetFocus. (Before trying to develop the code to move to a specific control, see what events are triggered when your no duplicate database code executes.)
 

Fernando

Registered User.
Local time
Today, 11:57
Joined
Feb 9, 2007
Messages
89
Hi, thanks for the response.
What happens is that the users tend to forget they have an instance of the db open (since the window is lost in the many windows they have open in the windows' start bar), so they try to open a new one. So what i would like to do is if they try to open a second instance, close automatically that instance and set the focus on the first instance of the db.
Now i just prompt a msgbox saying that theres an instance of the db already open, and then close the 2nd instance.
 

Fernando

Registered User.
Local time
Today, 11:57
Joined
Feb 9, 2007
Messages
89
I finally got it, since SW_RESTORE works but SW_SHOW doesn't, i just added a line to MINIMIZE the window and then RESTORE IT! to create the effect of focusing.
Code:
  'Instead of this:
  ...
  If apiIsIconic(hWndApp) Then
    apiShowWindowAsync hWndApp, SW_RESTORE
  Else
    apiShowWindowAsync hWndApp, SW_SHOW
  End If
  Application.Quit
  ...
  'Changed to this
  ...
  If apiIsIconic(hWndApp) Then
    apiShowWindowAsync hWndApp, SW_RESTORE
  Else
    apiShowWindowAsync hWndApp, 6 'Minimize Window
    apiShowWindowAsync hWndApp, SW_RESTORE
  End If
  ...
Hopefully this will help someone somewhere. This worked for Access 2k3 mde files.
 

Users who are viewing this thread

Top Bottom