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

2

5

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.

Laurielaurier answered 7/8, 2012 at 9:48 Comment(0)
R
14

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

Rapscallion answered 7/8, 2012 at 10:8 Comment(0)
G
4

For VBA, a simpler (and therefore possibly more portable) solution might be:

Application.UsableHeight
Application.UsableWidth

As found at Adjust userforms to fit in screen. I am using this successfully with Word 2007 VBA. In my case, Application.UsableWidth gives the actual screen width, Application.UsableHeight gives the actual screen height, minus the height of Windows' taskbar.

Gelt answered 30/1, 2017 at 15:52 Comment(3)
This is clever for using in MS Word, but in MS Access 2013 the .UsableWidth property does not seem to exist. Sure would be nice if it did, though.Osteoclasis
This dont work in MS Access, sadly.Acetone
You can use Word's library from Access like this: set wd = CreateObject("word.application") wd.UsableWidthHarriettharrietta

© 2022 - 2024 — McMap. All rights reserved.