Avatar of TerenceHewett
TerenceHewett
 asked on

Screen resolution - changing the Access view when resolution not the same as 1024x768

Hi experts,

Is it possible for Access to open up, check the screen resolution and change the users screen resolution temporarily to 1024x768, and then on close change the resolution back to what the user had before opening up my access db?

The situation is this: I have developed this database in a resolution of 1024x768 so all the forms fill the screen as required.  If the user has a resolution of 1280x1024 and then they open my database, the forms will only take up a smaller area of the screen, and from a GUI perspective, makes the whole database look unprofessional.  Hopefully the above explains my problem, but please let me know if I can offer further guidance to my problem.

Best regards and as usual, thanks.

Terry
Microsoft Access

Avatar of undefined
Last Comment
TerenceHewett

8/22/2022 - Mon
rockiroads

Yes, u can but have u thought of users having a screen resolution of 800x600?

Here is sample code that gets the current screen resolution
Simply place in a module


Public Declare Function GetSystemMetrics Lib "user32.dll" (ByVal nIndex As Long) As Long

Const SM_CXSCREEN = 0
Const SM_CYSCREEN = 1

Sub GetScreenSize()

    Dim x As Long, Y As Long, sYourMessage, iConfirm As Integer
    x = GetSystemMetrics(SM_CXSCREEN)
    Y = GetSystemMetrics(SM_CYSCREEN)
 
    MsgBox "Current screen size is " & x & " x " & Y & vbCrLf
   
End Sub


Now u can use x and y to determine whether screen needs resizing or not

rockiroads

The code I have for changing screen resolutions is this
Screen does go blank for a while though
Again add this code into a module
The function to call is this

ChangeDisplayResolution

Call it passing in your screen res
e.g.
ChangeDisplayResolution 1024, 768


Option Compare Database
Option Explicit

Private Const EWX_REBOOT = 2
Private Const CCDEVICENAME = 32
Private Const CCFORMNAME = 32
Private Const DM_BITSPERPEL = &H40000
Private Const DM_PELSWIDTH = &H80000
Private Const DM_PELSHEIGHT = &H100000
Private Const CDS_UPDATEREGISTRY = &H1
Private Const CDS_TEST = &H4
Private Const DISP_CHANGE_SUCCESSFUL = 0
Private Const DISP_CHANGE_RESTART = 1


Private Type typDevMODE
    dmDeviceName       As String * CCDEVICENAME
    dmSpecVersion      As Integer
    dmDriverVersion    As Integer
    dmSize             As Integer
    dmDriverExtra      As Integer
    dmFields           As Long
    dmOrientation      As Integer
    dmPaperSize        As Integer
    dmPaperLength      As Integer
    dmPaperWidth       As Integer
    dmScale            As Integer
    dmCopies           As Integer
    dmDefaultSource    As Integer
    dmPrintQuality     As Integer
    dmColor            As Integer
    dmDuplex           As Integer
    dmYResolution      As Integer
    dmTTOption         As Integer
    dmCollate          As Integer
    dmFormName         As String * CCFORMNAME
    dmUnusedPadding    As Integer
    dmBitsPerPel       As Integer
    dmPelsWidth        As Long
    dmPelsHeight       As Long
    dmDisplayFlags     As Long
    dmDisplayFrequency As Long
End Type

Private Declare Function EnumDisplaySettings Lib _
  "user32" Alias "EnumDisplaySettingsA" _
  (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, _
  lptypDevMode As Any) As Boolean

Private Declare Function ChangeDisplaySettings Lib _
  "user32" Alias "ChangeDisplaySettingsA" (lptypDevMode As Any, _
  ByVal dwFlags As Long) As Long
 
Private Declare Function ExitWindowsEx Lib _
  "user32" (ByVal uFlags As Long, _
  ByVal dwReserved As Long) As Long
 
Public Function ChangeDisplayResolution(NewWidth As Long, NewHeight As Long) As Boolean

    Dim typDM As typDevMODE
    Dim lRet As Long
    Dim iResp  As Integer
   
    lRet = EnumDisplaySettings(0, 0, typDM)
    If lRet = 0 Then Exit Function
   
    ' Set the new resolution.
    With typDM
        .dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
        .dmPelsWidth = NewWidth
        .dmPelsHeight = NewHeight
    End With
   
    lRet = ChangeDisplaySettings(typDM, CDS_UPDATEREGISTRY)
    Select Case lRet
        Case DISP_CHANGE_RESTART
            iResp = MsgBox("You must restart your computer to apply these changes." & vbCrLf & vbCrLf & "Restart now?", vbYesNo + vbInformation, "Screen Resolution Changed")
            If iResp = vbYes Then
                ChangeDisplayResolution = True
            End If
   
        Case DISP_CHANGE_SUCCESSFUL
            ChangeDisplayResolution = True
        Case Else
            ChangeDisplayResolution = False
    End Select

End Function



peter57r

Hi TerenceHewett,

You mess with MY screen setup and you won't see tomorrow(:-)

Pete
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
rockiroads

Pete, wot???

If u want to resize forms, have a look at this, see if it helps u http://www.jamiessoftware.tk/resizeform/rf_jump.html
rockiroads

Pete, the fun thing about changing resolutions is to have fun with the users

try changing resolution

ChangeDisplayResolution 768, 1024

instead of

ChangeDisplayResolution 1024, 768

LenaWood

I tried to do this once and forced my co-worker into getting a new monitor (then it still didn't work very well).  You have to remember that unless everyone that will be using this database has a fairly new monitor they may not be able to have the resolution set like you have it.  I know we have some older monitors here (ok I work for a company that has a contract with the government and we get new technology once it isn't so new - just got Office 2000) and setting the resolution like you want to just wouldn't work.  I had to set my monitor to the resolution that was used the most (or sneak in and change their resolution without them knowing it haha).

Good luck,
Lena
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
TerenceHewett

ASKER
Hi all,

Rocki, I have tried your code, and it works very well, except I need the code to recognise the users screen resolution at start up, change to 1024x768 and then change back to whatever the users screen resolution was prior to starting up my db.  Is this possible?

Regards,

Terry

PS: Thank you for all posts.  I have taken on board your comments.

rockiroads

I posted that code for you

look at the function GetScreenSize, it returns the current screen res
u then save those values somewhere, then revert to them when u need to
TerenceHewett

ASKER
Hi all, thanks for the posts.  Rocki, I have not forgotten this post.  As usual, I have been assigned to a number of different database projects and currently trying to juggle everything.  I think I had forgotten to add the code from the previous post with code in it with the GetScreenSize..I will try this asap.

Thanks for all your patience.

Regards,
Terry
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
rockiroads

No worries, take your time
TerenceHewett

ASKER
Hi all,

Rock, all is working except I cannot get the GetScreenSize to work in the way that I would like.  At the moment, I have all the code you gave me in a couple of modules. I have a screen resolution of 1024x768 which is also the best view for my users, but some users might have 1152x864 and others some other resolution.  The GetScreenSize does do its job in the fact that it puts a pop up on screen advising the current screen resolution, but I cannot find a way to store that information, change the resolution to 1024x768 and then revert the recorded screen resolution using GetScreenSize.  I am not seeing the wood through the trees on this, so apologise, but could do with some help here if its possible?

Very best wishes,


Terry  
ASKER CERTIFIED SOLUTION
rockiroads

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
TerenceHewett

ASKER
Rock, thank you for the above solution. Lena and Peter, thank you also for your posts.  Very much appreciated.

Regards,
Terry
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.