Search code examples
formsvbams-access

How to retrieve screen size/resolution in MS Access VBA to re-size a form


I have two popup forms (parent/child) that I want to be able to automatically re-size depending on the size of the screen.

How can I retrieve the size of the screen in order to achieve this.


Solution

  • For Access 2010 64 bit, you will need to add PtrSafe before Function.

    Declare Function GetSystemMetrics32 Lib "User32" _
        Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
    
    Sub ScreenRes()
    Dim w As Long, h As Long
        w = GetSystemMetrics32(0) ' width in points
        h = GetSystemMetrics32(1) ' height in points
    
    End Sub
    

    For VBA 64 bits

    Declare PtrSafe Function GetSystemMetrics32 Lib "User32" _
        Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
    

    More info: http://support.microsoft.com/kb/210603