Connecting Tech Pros Worldwide Forums | Help | Site Map

Is there a way to change screen resolution in VBA

lauren quantrell
Guest
 
Posts: n/a
#1: Nov 13 '05
Is there a way to force a change in a user's screen resolution using
VBA code without having any input from the user?
Example: User John Backwards has his screen set to 800 x 600 pixels.
Backwards loads an Access app that needs at least 1024 x 768 pixels so
the app, on load, changes the screen resolution for him to 1024 x 768.


lauren quantrell
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Is there a way to change screen resolution in VBA


Before I spark the ire of the community at large (is Larry online?) let
me revise my poorly prepared question (for which I have already
uncovered a solution)...
User John Backwards works in a mid-size company where he has been told
repeatedly that the minimum resolution for an enterprise level
application is 1024 x768. The application was developed for that spec
at a fairly large cost to the company and 1000+ users in many countries
over LAN/WAN/VPN connections use the application successfully. But poor
John Backwards calls tech support and puts in trouble tickets when, at
800 x 600 resolution, he can't see the bottom of certain forms or click
certain links.
Since poor John Backwards seems imune from termination, there seems to
be two solutions:
1.) force the screen to 1024 and maybe he (and a few of his cousins)
won't notice
2.) detect the 800 x 600 resolution and display a nasty message that
stays on his screen for maybe ten minutes explaining why he shouldn't
call tech support anymore when he can't perform certain actions.
There are probably other solutions but these two seem best for the
present mood.
lq

lauren quantrell
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Is there a way to change screen resolution in VBA


The code I found in this group to do this is below:


************************************************** ***************
' DECLARATIONS SECTION
'************************************************* ****************
Option Compare Database
Option Explicit
Type RECT
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type
' NOTE: The following declare statements are case sensitive.
Declare Function GetDesktopWindow Lib "User32" () As Long
Declare Function GetWindowRect Lib "User32" _
(ByVal hWnd As Long, rectangle As RECT) As Long
'================================================= =====
'This code shows how to change the screen resolution.
'Call the function like this:
' ChangeResolution 640, 480
'This would change the screen resolution to 640 pixels x 480 pixels.
Note
that
'you can only change the resolution to values supported by the display.

'Paste the following code into a module:'
Private Declare Function ChangeDisplaySettings Lib "User32" Alias _
"ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As
Long
Private Declare Function EnumDisplaySettings Lib "User32" Alias _
"EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As
_
Long, lpDevMode As Any) As Boolean
Const DM_PELSWIDTH = &H80000
Const DM_PELSHEIGHT = &H100000
Const CCFORMNAME = 32
Const CCDEVICENAME = 32
Private Type DEVMODE
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
Public Function Change_Resolution(iWidth As Single, iHeight As Single)
Dim DevM As DEVMODE
Dim a As Boolean
Dim i As Long
Dim b As Long
i = 0
'Enumerate settings
Do
a = EnumDisplaySettings(0&, i&, DevM)
i = i + 1
Loop Until (a = False)
'Change settings
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
DevM.dmPelsWidth = iWidth
DevM.dmPelsHeight = iHeight
b = ChangeDisplaySettings(DevM, 0)
End Function
'************************************************* ****************
' FUNCTION: GetScreenResolution()
'
' PURPOSE:
' To determine the current screen size or resolution.
'
' RETURN:
' The current screen resolution. Typically one of the following:
' 640 x 480
' 800 x 600
' 1024 x 768
'
'************************************************* ****************
Function GetScreenResolution() As String
Dim R As RECT
Dim hWnd As Long
Dim RetVal As Long
hWnd = GetDesktopWindow()
RetVal = GetWindowRect(hWnd, R)
GetScreenResolution = (R.x2 - R.x1) & "x" & (R.y2 - R.y1)
End Function

Tom van Stiphout
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Is there a way to change screen resolution in VBA


On 5 Aug 2005 19:12:05 -0700, "lauren quantrell"
<laurenquantrell@hotmail.com> wrote:

Thanks for that clarification. I fortunately got to this message
before I finished responding to your OP :-)

I still like the "bitch about the 'best viewed with' resolution, and
offer two choices: Adjust_Resolution, and Exit.

Sometimes people like John can be helped with a larger monitor. I've
worked with an organization with one scary user (I would not want to
meet her in traffic) who was at 640*480 on a 21" monitor, which was
all she could work with with her vision. The organization accommodated
her as much as possible, which I think is a good thing. Forcing her to
go to 1024 would mean a VERY large monitor or she would have to quit
her job...

-Tom.


[color=blue]
>Before I spark the ire of the community at large (is Larry online?) let
>me revise my poorly prepared question (for which I have already
>uncovered a solution)...
>User John Backwards works in a mid-size company where he has been told
>repeatedly that the minimum resolution for an enterprise level
>application is 1024 x768. The application was developed for that spec
>at a fairly large cost to the company and 1000+ users in many countries
>over LAN/WAN/VPN connections use the application successfully. But poor
>John Backwards calls tech support and puts in trouble tickets when, at
>800 x 600 resolution, he can't see the bottom of certain forms or click
>certain links.
>Since poor John Backwards seems imune from termination, there seems to
>be two solutions:
>1.) force the screen to 1024 and maybe he (and a few of his cousins)
>won't notice
>2.) detect the 800 x 600 resolution and display a nasty message that
>stays on his screen for maybe ten minutes explaining why he shouldn't
>call tech support anymore when he can't perform certain actions.
>There are probably other solutions but these two seem best for the
>present mood.
>lq[/color]

pietlinden@hotmail.com
Guest
 
Posts: n/a
#5: Nov 13 '05

re: Is there a way to change screen resolution in VBA


Let me preface this by saying that I know this question has been
answered... OTOH, If you haven't been there yet, have a look around
Randy Birch's site.

http://vbnet.mvps.org/

tons of great VB stuff. even has links in his page to copy the code to
the clipboard for you (except it doesn't work with Firefox, and IE is a
virus waiting to kill your computer). The content, though, is
incredibly helpful (and searchable).

Wayne Morgan
Guest
 
Posts: n/a
#6: Nov 13 '05

re: Is there a way to change screen resolution in VBA


The one thing I did notice when using the Change_Resolution function is that
it also changed my refresh rate to 60Hz instead of the 85 I was at. I don't
know if there is a way to set this also, probably is.

--
Wayne Morgan
MS Access MVP


"lauren quantrell" <laurenquantrell@hotmail.com> wrote in message
news:1123294476.474003.229300@z14g2000cwz.googlegr oups.com...[color=blue]
> The code I found in this group to do this is below:[/color]


Trevor Best
Guest
 
Posts: n/a
#7: Nov 13 '05

re: Is there a way to change screen resolution in VBA


Wayne Morgan wrote:[color=blue]
> The one thing I did notice when using the Change_Resolution function is that
> it also changed my refresh rate to 60Hz instead of the 85 I was at. I don't
> know if there is a way to set this also, probably is.
>[/color]

This can be set in your video driver if it supports it, NVidia ones have
an override feature that can be used to set a decent rate at each
resolution or there's utilities like RefreshLock that do it.
Wayne Morgan
Guest
 
Posts: n/a
#8: Nov 13 '05

re: Is there a way to change screen resolution in VBA


I know how to do it in the video driver, I was just wondering if the VBA
code that sets the resolution could also set the refresh rate.

--
Wayne Morgan
MS Access MVP


"Trevor Best" <nospam@nospam.invalid> wrote in message
news:42f70a40$0$323$da0feed9@news.zen.co.uk...[color=blue]
> Wayne Morgan wrote:[color=green]
>> The one thing I did notice when using the Change_Resolution function is
>> that it also changed my refresh rate to 60Hz instead of the 85 I was at.
>> I don't know if there is a way to set this also, probably is.
>>[/color]
>
> This can be set in your video driver if it supports it, NVidia ones have
> an override feature that can be used to set a decent rate at each
> resolution or there's utilities like RefreshLock that do it.[/color]


Trevor Best
Guest
 
Posts: n/a
#9: Nov 13 '05

re: Is there a way to change screen resolution in VBA


Wayne Morgan wrote:[color=blue]
> I know how to do it in the video driver, I was just wondering if the VBA
> code that sets the resolution could also set the refresh rate.
>[/color]

I tried before ('bout years ago when 43Hz interlaced was in use) and
couldn't do it, can't remember if it was a parameter on the change or
something that had to be done afterwards.
Closed Thread


Similar Microsoft Access / VBA bytes