WindowState Issue RRS feed

  • Question

  • I'm trying to get the WindowState of one of my forms,  I've found a lot of code, for example:  

    Sub GetWindowInfo()

    Dim lState As Long
        lState = Application.WindowState
        Select Case lState
            Case xlMaximized
                Debug.Print "Window is maximized."
            Case xlMinimized
                Debug.Print "Window is minimized."
            Case xlNormal
                Debug.Print "Window is normal." & vbCrLf
        End Select

    End Sub

    However, when I debug, I get a "Method or data member not found" error and .WindowState is highlighted.  I'm thinking I need to add a Reference, but nothing shows missing.

    Any ideas?

    Friday, April 5, 2019 11:10 PM


  • I have a few ideas. First, the code you found works for Excel, not Access.

    Second is an interesting semantics issue around the word "missing". No reference shows missing because none of the selected references are missing. They are present on your system. Access isn't smart enough, nor could it be, to look at your code and say: that WOULD compile if only you had a reference to X, so X is missing. 
    And don't add a reference to Excel. That won't solve the problem because Access' Application object does not have a WindowsState property, and never will, regardless of which references you select.

    Third, here is a solution using Windows API calls. Forms have a window handle property .Hwnd

    Yes, the link is for another programming language, but it's close enough you can start to figure it out.

    -Tom. Microsoft Access MVP

    • Marked as answer by Kenrav Saturday, April 6, 2019 1:08 PM
    Saturday, April 6, 2019 1:54 AM