[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Make minimized application window visible

Posted on 2006-04-29
17
Medium Priority
?
361 Views
Last Modified: 2008-03-10
If the application window of an instance of Access is minimized, how can you make the application window visible to the user via automation?
0
Comment
Question by:Milewskp
  • 5
  • 5
  • 4
  • +2
17 Comments
 
LVL 4

Expert Comment

by:paulgrunner
ID: 16570236
try this one:
Application.RunCommand acCmdAppMaximize

or

Application.RunCommand acCmdAppRestore
0
 
LVL 58

Expert Comment

by:harfang
ID: 16570341
Hello again,

To add to the previous, an automated instance is normally not minimized, but rather invisible. Try this:

    Dim appACC As Access.Application
   
    Set appACC = CreateObject("Access.Application")
    appACC.Visible = True
    ' if needed:
    ' appACC.RunCommand acCmdAppRestore
    ' later vesions?
    ' appACC.WindowState = ??Normal

Also, pay attention to the .UserControl property. If True, the instance will no longer close when going out of scope. If False, it will try to close at least...

Cheers!
(°v°)
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 16570385
If the application is already running, you might also want to consider Putfocus (API) in conjunction with grabbing the application object's hwnd.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 1

Author Comment

by:Milewskp
ID: 16570547
paulgrunner and harfang,

The functions:
   Application.RunCommand acCmdAppMaximize
   Application.RunCommand acCmdAppRestore

change the size of the window, but don't bring it to the foreground.

-----------------------------
LPurvis,

I tried this:

   Public Declare Function PutFocus Lib "user32" Alias "Setfocus" (ByVal hWnd as Long) as Long
   Dim varHw as variant

   Set appACC = GetObject(...

   varHw = PutFocus(appACC.hWndAccessApp)

but nothing happened (note: the Access app was previously opened by a user and still running).

Any ideas?

0
 
LVL 1

Author Comment

by:Milewskp
ID: 16570570
I also tried:

    Declare Function SetActiveWindow Lib "user32.dll" (ByVal hwnd As Long) As Long

This also had no effect.
0
 
LVL 58

Accepted Solution

by:
harfang earned 2000 total points
ID: 16570597
Hello,

> "[...] bring it to the foreground"
You didn't ask for that ;)

Quick hack version:
    appACC.RunCommand acCmdAppMinimize
    appACC.RunCommand acCmdAppRestore

Cleaner:

Declare Function AppActivate Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Long

    varHw = AppActivate(appACC.hWndAccessApp)
    appACC.RunCommand acCmdAppRestore

Cheers!
(°v°)
0
 
LVL 58

Expert Comment

by:harfang
ID: 16570604
LOL,

Another quick hack... ;)

    FollowHyperlink appACC.CurrentDb.Name

(°v°)
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 16570685
or there's
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
and hence
SetForegroundWindow appACC.hWndAccessApp

(I'd just taken the need for a setfocus component from the part of the question "make the application window visible" :-)
0
 
LVL 58

Expert Comment

by:harfang
ID: 16570773
<!-- Leigh, you are 45m late with that WinAPI call ... ;) -->
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 16571994
<Well, if you're gonna hide it amongst about 30 other good ideas... ;-P>
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 16631217
Milewskp,

I typically use this to restore the database window and give it the focus (Bring it to the Foreground):

    'Select a Form item (in the database window)
    DoCmd.SelectObject acForm, "AnyForm", True
    '*NOW* you can Retsore the database window
    DoCmd.Restore

(The key is Selecting an Object first, then doing the restore)

See if this helps
0
 
LVL 1

Author Comment

by:Milewskp
ID: 16648964
Hi boag2000,
Is not the database window I'm interested in, it's the application window.
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 16649006
And none of the suggestions from Markus that I didn't see and just blindly repeated worked? :-S
0
 
LVL 1

Author Comment

by:Milewskp
ID: 16649026
Hi Leigh,
I can't try those suggestions for a while. Will keep you posted.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 16652740
Milewskp,
<Is not the database window I'm interested in, it's the application window.>
OK.
0
 
LVL 1

Author Comment

by:Milewskp
ID: 16686956
Harfang, thanks for the AppActivate  API function - it did the trick. Here is what I used to bring Access to the fore ground from within Excel:

Public Declare Function AppActivate Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Long

 Set Acc = GetObject(ThisWorkbook.Path & "\" & DbName)
    ThisHwnd = AppActivate(Acc.hWndAccessApp)   'Bring the Access application to the fore.
    If ThisHwnd = Null Then 'There was a problem accessing the Acc window
        Beep
        MsgBox "There was a problem. Macro will now quit."
        End
    Else
        Acc.RunCommand acCmdAppMaximize
    End If
0
 
LVL 58

Expert Comment

by:harfang
ID: 16688155
Hello Milewskp

I realised later that my choice of "AppActivate" for a name was probably not too good. AppActivate is in fact a built-in method, but it expects the caption of the application to activate, not the hWnd. So from Access, the application "appXL" can be activated with "AppActivate appXL.Caption". I believe that recent versions of Access also expose their Application.Caption property...

You should probably keep the original name of the API call, as Leigh suggested in {http:#16570685} btw...

Anyway, good luck with your project!
(°v°)
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question