[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 639
  • Last Modified:

Access Form Resize

How do I make an access form automatically resize itself depending on the screen resolution of the monitor? I think there is an API function to do this but I really don't know. Any ideas and samples would be very useful.
1 Solution
I'm sure that you've thought of this, but who knows....?

Access has--built-in--Auto Resize, and Auto Center, which do this to a degree.  The form will be the right size to show all of its elements, and irrespective of resolution will be centered on the monitor.

Can you be more detailed about what you are trying to do?

Hi, lcleary, there's some graet utils for this and other things at www.fmsinc.com.  One is called Zoom.  Might be worthwhile to check it out.

good luck as usual...

Ken Getz's book (Access 97 Developers Handbook) covers the "scaling" of forms pretty good. It starts on page 465 under Screen Resolution. Some of the declares you will use include:

Public Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As RECT) As Long

Public Declare Function GetClientRect Lib "user32" Alias "GetClientRect" (ByVal hwnd As Long, lpRect As RECT) As Long

etc. Good luck

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Other way:
1. Get current resolution :
Global Const WM_HORZRES = 8
Global Const WM_VERTRES = 10

Declare Function WM_apiGetDeviceCaps _
Lib "gdi32" Alias "GetDeviceCaps" _
(ByVal hdc As Long, ByVal nIndex As Long) As Long
Declare Function WM_apiGetDesktopWindow _
Lib "user32" Alias "GetDesktopWindow" () As Long
Declare Function WM_apiGetDC _
Lib "user32" Alias "GetDC" _
(ByVal hwnd As Long) As Long
Declare Function WM_apiReleaseDC _
Lib "user32" Alias "ReleaseDC" _
(ByVal hwnd As Long, ByVal hdc As Long) As Long
Declare Function WM_apiGetSystemMetrics _
Lib "user32" Alias "GetSystemMetrics" _
(ByVal nIndex As Long) As Long

Function xg_GetScreenResolution(DisplayHeight As Integer, DisplayWidth As Integer) As String
'return the display height and width
'Dim DisplayHeight As Integer
'Dim DisplayWidth As Integer
Dim hDesktopWnd As Long
Dim hDCcaps As Long
Dim iRtn As Integer

'* make API calls to get desktop settings
hDesktopWnd = WM_apiGetDesktopWindow() 'get handle to desktop
hDCcaps = WM_apiGetDC(hDesktopWnd) 'get display context for desktop
DisplayHeight = WM_apiGetDeviceCaps(hDCcaps, WM_VERTRES)
DisplayWidth = WM_apiGetDeviceCaps(hDCcaps, WM_HORZRES)
iRtn = WM_apiReleaseDC(hDesktopWnd, hDCcaps) 'release display context

'MsgBox "Desktop display width is " & DisplayWidth & " pixels."
'MsgBox "Desktop display height is " & DisplayHeight & " pixels."

xg_GetScreenResolution = DisplayWidth & "x" & DisplayHeight

End Function
2. Get old resolution and if old <>
   current, resize form:
Private Sub Convert(x As Integer, xOld As Integer, _
                    y As Integer, yOld As Integer)
   Dim fForm As Form, iControl As Control
   Dim DB As Database
   Dim i As Integer
   Dim xMax As Integer, yMax As Integer
   Set DB = CurrentDb()
            DoCmd.OpenForm "MyForm", acDesign, , , acFormPropertySettings, acHidden
     Set fForm = [Forms]![MyForm]
     xMax = 0
     yMax = 0
     For Each iControl In fForm.Controls
          With iControl
             .Height = .Height * y / yOld
             .Width = .Width * x / xOld
             .Left = .Left * x / xOld
             .Top = .Top * y / yOld
             On Error Resume Next
             .FontSize = .FontSize * y / yOld
             If .FontSize < 8 Then .FontSize = 8
             If .ControlType = acLabel Then
                .SizeToFit 'first buttons!
             End If
             xMax = IIf(.Left + .Width > xMax, .Left + .Width, xMax)
             yMax = IIf(.Top + .Height > yMax, .Top + .Height, yMax)
          End With
       'End If
     Next iControl
     fForm.Width = xMax + 10
     fForm.Detail.Height = yMax + 10
     DoCmd.Close acForm, "MyForm", acSaveYes
End Sub

Happy New Year. Alex
lcleary:  Welcome to EE.

FMS, as Tom mentioned, makes two resizing products - Form Resizer, which is part of their Access Components package and Sizer, which is a VB 5/6 ActiveX control.  No one to my knowledge has really tried Sizer with Access but with some playing with it might work.

The Forms Resizer will allow a user to increase the size of a form to fill a window with higher resolution.  If there are several subforms within the form, they will resize also.

We have used the product but remed it out while we were developing the product as the ActiveX caused all kinds of additional problems in the development cycle.  We shipped the first release with 800 X 600 resolution and so far, no one has complained about it.

Icleary, what do you think about all
Icleary, sorry, that i answer, what we
want you reaction:
what do you think about all
prepositions? What(and who) helps you ?
Sorry again, Alex

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now