Results 1 to 4 of 4
  1. #1
    jsunnb is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2013
    Location
    Southern California
    Posts
    9

    Red face Run VBA code when Access window is no longer Minimized

    Hopefully this isn't too confusing, but I need a way to run VBA code when Access is no longer minimized.

    Background:
    I have a database where I've been using the Popup feature on my forms but I hide access window using the following code: (found it online, but it does exactly what I needed)
    Code:
    Private Declare Function apiShowWindow Lib "User32" _
        Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    
    Function fSetAccessWindow(nCmdShow As Long)
    
    Dim loX As Long
    Dim loForm As Form
    On Error Resume Next
    Set loForm = Screen.ActiveForm
    
    If Err <> 0 Then
    loX = apiShowWindow(hWndAccessApp, nCmdShow)
    Err.Clear
    End If
    
    If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Then
    MsgBox "Cannot minimize Access with " _
    & (loForm.Caption + " ") _
    & "form on screen"
    ElseIf nCmdShow = SW_HIDE And loForm.PopUp <> True Then
    MsgBox "Cannot hide Access with " _
    & (loForm.Caption + " ") _
    & "form on screen"
    Else
    loX = apiShowWindow(hWndAccessApp, nCmdShow)
    End If
    fSetAccessWindow = (loX <> 0)
    End Function
    So when us Call Hide_App_Window.fSetAccessWindow(#), where the # is a number 0-3, I get these results.
    0 = Hide (can't see access window, or the access icon on the task bar)
    1 = Normal View
    2 = Minimized


    3 = Maximized

    The problem I'm having is when I use 0 the user can't minimize it. So I created a button that does that (Call Hide_App_Window.fSetAccessWindow(2)) but now when the user clicks on it in the taskbar to make it visible (technically normal view) you see the access window when it opens back up.
    I need someway of running the Call Hide_App_Window.fSetAccessWindow(0) code anytime access is no longer minimized.

    Any ideas would be more than welcome. Also, put some jpgs of what I want to happen and not happen below

    Thank you very much!
    Click image for larger version. 

Name:	Undesired View.jpg 
Views:	11 
Size:	187.7 KB 
ID:	10659Click image for larger version. 

Name:	Desired View.jpg 
Views:	10 
Size:	141.5 KB 
ID:	10660

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Only thing I can think of is to call this function from the GotFocus event of each form.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    jsunnb is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2013
    Location
    Southern California
    Posts
    9
    I was thinking that too, but when it's returns from minimized, the "On GetFocus" doesn't run, but I suppose I could still put it in there and when they tried to use anything on the DB it would at least run the code.

    I'm going to hold off on marking this as solved to give others a chance to answer, but maybe in a week or so I'll update it if no one has yet.

    Thank you.

  4. #4
    jsunnb is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2013
    Location
    Southern California
    Posts
    9
    Turns out the "On GetFocus" doesn't run when someone just clicks on the form.... so sadly I still don't have a solution.
    I also tried a few other events that I thought might run when someone starts using anything on the form, but still no luck.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Window Access Minimized/Maximized Problem
    By PATRICK in forum Programming
    Replies: 2
    Last Post: 09-18-2012, 06:25 AM
  2. Replies: 16
    Last Post: 06-21-2012, 10:00 PM
  3. Excel automation (open minimized)
    By jfgrenier in forum Programming
    Replies: 2
    Last Post: 11-06-2011, 05:53 AM
  4. Replies: 1
    Last Post: 08-17-2011, 01:43 PM
  5. Access Window On top
    By Jas_The_Ace in forum Programming
    Replies: 0
    Last Post: 02-28-2009, 04:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums