Microsoft KB Archive/113458

= ACC: How to Determine the Current Screen Resolution (1.x/2.0) =

Article ID: 113458

Article Last Modified on 5/6/2003

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition

-



This article was previously published under Q113458



SUMMARY
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article describes a sample user-defined Access Basic function that you can use to determine the current screen resolution. This function is useful in determining if you are running in standard VGA mode (640 x 480) or Super VGA mode (800 x 600 or 1024 x 768).

This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information on Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x, or the "Building Applications" manual in version 2.0.



MORE INFORMATION
The example below demonstrates how to create and use the sample GetScreenResolution function.

Notes:


 * You may have some Microsoft Windows API functions defined in an existing Microsoft Access library; therefore, your declarations may be duplicates. If you receive a duplicate procedure name error message, remove or comment out the declarations statement in your code.
 * In the following sample code, an underscore (_) is used as a line- continuation character. Remove the underscores when re-creating this code in Access Basic.
 * In Microsoft Access version 2.0, you can create code in a form module. Code in a form module is restricted to that form. The Type statement used in this example must be global. You can use this code in a form's module if the Type statement is in the Declarations section of a global Access Basic module. For more information about the Type statement, search for "type" then "Type Statement" using the Microsoft Access Help menu.

  Create a new module, and type the following Declarations and function:

'     *****************************************************************      ' DECLARATIONS SECTION

Option Explicit

Type RECT x1 As Integer y1 As Integer x2 As Integer y2 As Integer End Type

Declare Function GetDesktopWindow Lib "User" As Integer Declare Function GetWindowRect Lib "User" _ (ByVal hWnd As Integer, rectangle As RECT) As Integer

'     *****************************************************************      ' 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 Integer Dim RetVal As Integer hWnd = GetDesktopWindow RetVal = GetWindowRect(hWnd, R)         GetScreenResolution = (R.x2 - R.x1) & "x" & (R.y2 - R.y1) End Function  From the View menu, choose Immediate Window. Type the following line in the Immediate window, and then press ENTER:

? GetScreenResolution 

The current screen resolution will be displayed in the Immediate window. If the current resolution is standard VGA, the following will be displayed in the Immediate window:

  640x480

