Results 1 to 12 of 12
  1. #1
    DTO. is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Dec 2020
    Posts
    48

    How can we retrieve the current monitor's size with VBA to resize the forms automatically?


    Hello all,

    I need to retrieve the monitor's size which my form currently located in. In this way, I thought I will be able to automatically resize the forms based on current monitor's size.

    As a first step I would like to get your help to get the current monitor's size. (There are three size which can be choosen: %100, %125, %150)

    I have designed my forms based on %150 size. But some users are using %100 some are using %125. Therefore it is becoming small in their screens.

    Thanks for help

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Where do users set this %?

    If you want to get monitor's resolution info, review https://riptutorial.com/vba/example/...een-resolution
    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
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Suggest you read my 3 part article on automatic form resizing (AFR): Automatic Form Resizing - Mendip Data Systems
    It includes code to detect screen resolution...and much more
    As a general rule, you should design for the lowest resolution / smallest monitor as AFR works best when scaling up
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  4. #4
    DTO. is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Dec 2020
    Posts
    48
    Quote Originally Posted by June7 View Post
    Where do users set this %?

    If you want to get monitor's resolution info, review https://riptutorial.com/vba/example/...een-resolution
    Hello June7,

    İt is here I send you the screenshot. As you can see it is for example set %125 below. That can be %100, 125 or 150 in different users.
    I am therefore not mentioning about resolution. I would like to get this scale and layout with VBA.

    Click image for larger version. 

Name:	scale and layout.JPG 
Views:	46 
Size:	40.0 KB 
ID:	44735

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    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.

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    I found the same link. Unfortunately it doesn't help.

    I also tried looking through the various settings in System Metrics - that didn't help either
    I don't know if its possible to do in VBA. I anticipate an API call will be needed if a solution is possible.
    The only other possibility is to find a registry setting that stores the current scaling.

    If that can be identified, I have code to read the registry
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,429
    don't have time to investigate thoroughly but according to this link

    https://docs.microsoft.com/en-us/win...ingdi-devmodea

    you'll find the scaling there

    how you get to it? this not very helpful link might point you in the right direction
    https://stackoverflow.com/questions/...splay-settings

    it lead me to determine the info is in winuser.h which in turn lead me to

    https://docs.microsoft.com/en-us/win...changebehavior

    also worth searching for is 'WM_GETDPISCALEDSIZE '

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Following Ajax's post, it may well be that the scaling can be retrieved using WMI code.

    However, I don't believe its in any way necessary if you use automatic form resizing.
    I've just retested the example AFR app supplied as part of the link article referenced in post #3.
    I tested each of the 3 forms at the default 100% scaling and at 125%, 150% & 175%.
    Each form fitted the screen almost perfectly even at such large scaling factors
    I didn't test with advanced scaling settings (up to 500% possible) as I've never known anyone use anything bigger than 150% in practice

    So before spending any further time trying to determine the scaling factor using VBA, I again recommend you try automatic form resizing.
    Its main purpose is to handle different screen resolutions, monitor sizes and shapes (form factors). Handling scaling is another bonus.
    .
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  9. #9
    keviny04 is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Apr 2015
    Posts
    128
    Access should resize every window automatically using the scale set in Windows Display settings. At 3840x2160 resolution and 100% scale, my forms look tiny. At 175% scale, Windows automatically enlarges them. I don't have to change form sizes in Access. But what I do have to change are form objects that have fixed sizes, such as images. On my forms, I need to have small and large versions of the images, which need to retrieved according to the screen resolution. You can get screen res by calling an internal Windows function:

    Code:
    Declare Function GetSystemMetrics32 Lib "User32" _
        Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
    
    Function GetScreenResHeight() As Long
        GetScreenResHeight = GetSystemMetrics32(1)
    End Function
    
    Function GetScreenResWidth() As Long
        GetScreenResWidth = GetSystemMetrics32(0)
    End Function

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    For info, automatic form resizing also automatically resizes all form controls including images. No need to have
    small and large versions of the images, which need to retrieved according to the screen resolution.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  11. #11
    keviny04 is offline Competent Performer
    Windows 7 64bit Office 365
    Join Date
    Apr 2015
    Posts
    128
    Quote Originally Posted by isladogs View Post
    For info, automatic form resizing also automatically resizes all form controls including images. No need to have
    Images put on command buttons cannot be resized. You cannot "stretch" or "fill" the image to the button size like what you can do for an image control.

  12. #12
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Quote Originally Posted by keviny04 View Post
    Images put on command buttons cannot be resized. You cannot "stretch" or "fill" the image to the button size like what you can do for an image control.
    That's true.
    However, to be honest, I've never found that to be a problem in my own applications.
    Of course, its also possible to use an image control as a 'command button' in which case it resizes perfectly
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Replies: 7
    Last Post: 03-29-2020, 09:34 AM
  2. Replies: 1
    Last Post: 08-26-2017, 01:15 PM
  3. Sizing Forms to fit monitor
    By data808 in forum Forms
    Replies: 0
    Last Post: 02-25-2014, 02:03 AM
  4. Resize form automatically
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-30-2010, 10:24 PM
  5. Replies: 1
    Last Post: 04-29-2010, 05:15 PM

Tags for this Thread

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