By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 992 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

Any good Form Resizing code?

P: n/a
I have some old code that I use from the Access 95 Developers handbook. The
code works very well, with the exception that it doesn't seem to recognize
wide screens, and sizes tab controls so that they are too big and wind up
covering up some of the fields on the main form.

Is there any good code out there that works in a similar fashion that will
also either a) stretch the form width wise on widescreens or b), rely on
height rather than width to resize the form. My VB skill isn't that great,
so I'm not able to modify this code to do what I want. (I've pasted the
code I'm using below).

Any ideas?

Thanks!


Option Compare Database 'Use database order for string comparisons
Option Explicit

' From Microsoft Access 95 Developer's Handbook
' by Litwin, Getz, Gilbert, and Reddick (Sybex)
' Copyright 1995. All rights reserved.

' Store rectangle coordinates.
Type glrTypeRect
X1 As Long
Y1 As Long
X2 As Long
Y2 As Long
End Type

Declare Function glr_apiIsIconic Lib "user32" _
Alias "IsIconic" (ByVal hwnd As Long) As Long

Declare Function glr_apiGetDeviceCaps Lib "gdi32" _
Alias "GetDeviceCaps" (ByVal hdc As Long, _
ByVal nIndex As Long) As Long

Declare Function glr_apiGetWindowRect Lib "user32" _
Alias "GetWindowRect" (ByVal hwnd As Long, _
lpRect As glrTypeRect) As Long

Declare Function glr_apiGetParent Lib "user32" _
Alias "GetParent" (ByVal hwnd As Long) As Long

Declare Function glr_apiGetClientRect Lib "user32" _
Alias "GetClientRect" (ByVal hwnd As Long, _
lpRect As glrTypeRect) As Long

Declare Function glr_apiGetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As Long

Declare Function glr_apiGetSystemMetrics Lib "user32" _
Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long

Declare Function glr_apiGetSystemMenu Lib "user32" _
Alias "GetSystemMenu" (ByVal hwnd As Long, _
ByVal bRevert As Long) As Long

Declare Function glr_apiGetActiveWindow Lib "user32" _
Alias "GetActiveWindow" () As Long

'================================================= ======================

' Store group/subform dimensions.
Type glrTypeDimensions
sglLeft As Single
sglTop As Single
sglWidth As Single
sglHeight As Single
strCtlName As String
End Type

' These are the class names used in Access.
Public Const glrcAccessClass = "OMain"
Public Const glrcMDIClientClass = "MDICLIENT"
Public Const glrcAccessDBCClass = "ODb"
Public Const glrcAccessFormClass = "OForm"

' Windows API declarations.
Declare Function glr_apiCreateIC Lib "gdi32" _
Alias "CreateICA" (ByVal lpDriverName As String, _
ByVal lpDeviceName As String, ByVal lpOutput As String, _
lpInitData As Any) As Long

Declare Function glr_apiDeleteDC Lib "gdi32" _
Alias "DeleteDC" (ByVal hdc As Long) As Long

Declare Function glr_apiMoveWindow Lib "user32" _
Alias "MoveWindow" (ByVal hwnd As Long, _
ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal bRepaint As Long) As Long

Declare Function glr_apiSetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Declare Function glr_apiEnableMenuItem Lib "user32" _
Alias "EnableMenuItem" (ByVal hMenu As Long, _
ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long

Declare Function glr_apiGetWindow Lib "user32" _
Alias "GetWindow" (ByVal hwnd As Long, ByVal wCmd As Long) As Long

Declare Function glr_apiGetClassName Lib "user32" _
Alias "GetClassNameA" (ByVal hwnd As Long, _
ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Declare Function glr_apiFindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Declare Function glr_apiGetNextWindow Lib "user32" _
Alias "GetNextWindow" (ByVal hwnd As Long, _
ByVal wFlag As Long) As Long

Declare Function glr_apiSetFocus Lib "user32" _
Alias "SetFocus" (ByVal hwnd As Long) As Long

' Get a string from a private INI file. Returns the number of bytes
' copied into strReturned, not including the trailing null.
Declare Function glr_apiGetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpDefault As String, _
ByVal lpReturnedString As String, ByVal nSize As Long, _
ByVal lpFileName As String) As Long

' Write a string to a private INI file. Returns a non-zero value if
successful,
' otherwise it returns a 0.

Declare Function glr_apiWritePrivateProfileString Lib "kernel32" _
Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As
String) As Long

' These functions aren't actually used
' but are provided here for reference only.

' Get a string from WIN.INI. Returns the number of bytes copied into
strReturned,
' not including the trailing null.
Declare Function glr_apiGetProfileString Lib "kernel32" _
Alias "GetProfileStringA" (ByVal lpglrcAppName As String, _
ByVal lpKeyName As String, ByVal lpDefault As String, _
ByVal lpReturnedString As String, ByVal nSize As Long) As Long

' Get an integer from WIN.INI. Returns either the integer it found,
' or the value sent in intDefault.
Declare Function glr_apiGetProfileInt Lib "kernel32" _
Alias "GetProfileIntA" (ByVal lpglrcAppName As String, _
ByVal lpKeyName As String, ByVal nDefault As Long) As Long

' Write a string to WIN.INI. Returns a non-zero value if successful,
' otherwise it returns a 0.
Declare Function WriteProfileString Lib "kernel32" _
Alias "WriteProfileStringA" (ByVal lpszSection As String, _
ByVal lpszKeyName As String, ByVal lpszString As String) As Long

' Get an integer from a private INI file. Returns either the integer it
found,
' or the value sent in intDefault.
Declare Function GetPrivateProfileInt Lib "kernel32" _
Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal nDefault As Long, _
ByVal lpFileName As String) As Long

' GetNextWindow() constants
Public Const glrcGW_CHILD = 5
Public Const glrcGW_HWNDNEXT = 2

' Action constants
Public Const glrcMF_BYCOMMAND = &H0
Public Const glrcMF_DISABLED = &H2
Public Const glrcMF_ENABLED = &H0
Public Const glrcMF_GRAYED = &H1

' Menu item name constants
Public Const glrcSC_SIZE = &HF000
Public Const glrcSC_MOVE = &HF010
Public Const glrcSC_MINIMIZE = &HF020
Public Const glrcSC_MAXIMIZE = &HF030
Public Const glrcSC_NEXTWINDOW = &HF040
Public Const glrcSC_CLOSE = &HF060
Public Const glrcSC_RESTORE = &HF120

' Windows API Constants
Public Const glrcVERTRES = 10
Public Const glrcHORZRES = 8
Public Const glrcLOGPIXELSX = 88
Public Const glrcLOGPIXELSY = 90

' General Constants
Public Const glrcTwipsPerInch = 1440

' GetWindowLong Constant
Public Const glrcGWL_STYLE = -16

' Windows Style constant
Public Const glrcWS_CAPTION = &HC00000

' System Metrics Constant
Public Const glrcSM_CYCAPTION = 4
Public Const glrcSM_CXFULLSCREEN = 16
Public Const glrcSM_CYFULLSCREEN = 17

Function IsSubForm(frm As Form) As Boolean
' Is the form referenced in the
' parameter currently loaded as a subform?
' Check its Parent property to find out.

' From Microsoft Access 95 Developer's Handbook
' by Litwin, Getz, Gilbert, and Reddick (Sybex)
' Copyright 1995. All rights reserved.

' In:
' frm: a reference to the form in question
' Out:
' Return value: True if the form is a subform
' False if it's a standalone form
Dim strName As String
On Error Resume Next
strName = frm.Parent.name
IsSubForm = (Err = 0)
On Error GoTo 0
End Function

Option Compare Database 'Use database order for string comparisons
Option Explicit

' From Microsoft Access 95 Developer's Handbook
' by Litwin, Getz, Gilbert, and Reddick (Sybex)
' Copyright 1995. All rights reserved.

' Constants that aren't there, that probably should be.
Const acWindow = 7
Const acSizeToFit = 6
Const acDatasheetView = 2

' Enumerated constants for GetTwips()
Const glrcXAxis = 0
Const glrcYAxis = 1

' The maximum size for a form is 22 inches.
Const glrcMaxTwips = 22 * glrcTwipsPerInch

' These constants should not require changing.
' 1280x1024, 1024x768 use 12 and 12.
' 640x480 and 800x600 use 15 and 15.
'
Const glrcDesignXTwipsLoRes = 15
Const glrcDesignYTwipsLoRes = 15
Const glrcDesignXTwipsHiRes = 12
Const glrcDesignYTwipsHiRes = 12

' Keep track of the previous/original size for the form.
' Dim rctOriginal As glrTypeRect

' Error constants
Const glrcErrDivisionByZero = 11
Const glrcErrInvalidProperty = 2455

Private Function ChangeFont(Ctl As Control) As Boolean

' Decide whether or not to change the font,
' based on the control type.

Dim fDoit As Integer
fDoit = False
Select Case Ctl.ControlType
Case acTextBox, acComboBox, acListBox, acLabel, _
acCommandButton, acToggleButton
fDoit = True
Case Else
fDoit = False
End Select
ChangeFont = fDoit
End Function

Private Function ChangeHeight(Ctl As Control) As Boolean

' Decide whether or not to change the height,
' based on the control type.

Dim fDoit As Integer
fDoit = True
Select Case Ctl.ControlType
Case acCheckBox, acOptionButton, acPageBreak, acPage
fDoit = False
Case Else
fDoit = True
End Select
ChangeHeight = fDoit
End Function

Private Function FixGroups(frm As Form, aGroups() As glrTypeDimensions,
sglFactorX As Single, sglFactorY As Single)

' Store away information about controls that
' contain other controls (subforms/subgroups).
' Return the number of these controls that
' were found.

Dim intI As Integer
Dim fDoit As Boolean
Dim intGroups As Integer

intGroups = 0
For intI = 0 To frm.Count - 1
With frm(intI)
Select Case .ControlType
Case acOptionGroup, acSubform
fDoit = True
Case Else
fDoit = False
End Select
If fDoit Then
intGroups = intGroups + 1
ReDim Preserve aGroups(intGroups)

aGroups(intGroups).strCtlName = .name
aGroups(intGroups).sglLeft = .Left * sglFactorX
aGroups(intGroups).sglTop = .Top * sglFactorY
aGroups(intGroups).sglWidth = .Width * sglFactorX
aGroups(intGroups).sglHeight = .Height * sglFactorY
End If
End With
Next intI
FixGroups = intGroups
End Function

Private Sub FixSections(frm As Form, sglFactorY As Single)

' Loop through all the sections of the form,
' up to 5 sections, setting the height of
' each. If a section isn't there, just keep
' on going.

Dim intI As Integer
Dim varTemp As Variant

' There are 5 possible sections in a form,
' but they might not all be there.
On Error Resume Next
With frm
For intI = 0 To 4
varTemp = .Section(intI).Height * sglFactorY
.Section(intI).Height = IIf(varTemp > glrcMaxTwips,
glrcMaxTwips, varTemp)
Next intI
End With
End Sub

Private Sub GetFormSize(frm As Form, rct As glrTypeRect)

' Fill in rct with the coordinates of the window.

Dim hWndParent As Long
Dim rctParent As glrTypeRect

' Find the position of the window in question, in
' relation to its parent window (the Access desktop,
' the MDIClient window).
hWndParent = glr_apiGetParent(frm.hwnd)

' Get the coordinates of the current window and its parent.
glr_apiGetWindowRect frm.hwnd, rct

' Catch the case where the form is Popup (that is,
' its parent is NOT the Access main window.) In that
' case, don't subtract off the coordinates of the
' Access MDIClient window.
If hWndParent <> Application.hWndAccessApp Then
glr_apiGetWindowRect hWndParent, rctParent

' Subtract off the left and top parent coordinates, since you
' need coordinates relative to the parent for the
glr_apiMoveWindow()
' function call.
With rct
.X1 = .X1 - rctParent.X1
.Y1 = .Y1 - rctParent.Y1
.X2 = .X2 - rctParent.X1
.Y2 = .Y2 - rctParent.Y1
End With
End If
End Sub

Private Sub GetScreenScale(intX As Integer, intY As Integer, sglFactorX As
Single, sglFactorY As Single)
' In: intX, intY: x and y screen resolutions
' when the form was created.
' Out: sglFactorX, sglFactorY: scaling factors for
' the x and y directions.

Dim intScreenX As Integer
Dim intScreenY As Integer

Dim intTwipsPerPixelX As Integer
Dim intTwipsPerPixelY As Integer

Dim lngIC As Long

On Error GoTo GetScreenScaleError

' Get the information context you need to find the screen info.
lngIC = glr_apiCreateIC("DISPLAY", vbNullString, _
vbNullString, vbNullString)

' If the call to CreateIC didn't fail, then get the info.
If lngIC <> 0 Then
' Find the number of pixels in both directions on the
' screen, (640x480, 800x600, 1024x768, 1280x1024?). This
' also takes into account the size of the task bar, whereever
' it is.
intScreenX = glr_apiGetSystemMetrics(glrcSM_CXFULLSCREEN)
intScreenY = glr_apiGetSystemMetrics(glrcSM_CYFULLSCREEN)

' Find the number of twips per pixel in both directions.
intTwipsPerPixelX = glrcTwipsPerInch / glr_apiGetDeviceCaps(lngIC,
glrcLOGPIXELSX)
intTwipsPerPixelY = glrcTwipsPerInch / glr_apiGetDeviceCaps(lngIC,
glrcLOGPIXELSY)

' Release the information context.
glr_apiDeleteDC lngIC

' Get the ratio of the current screen size to the design-time
' screen size.

sglFactorX = intScreenX / intX
sglFactorY = intScreenY / intY

' Finally, take into account the differences in the display
' resolutions. At 640x480, you get more twips per pixel (15)
' as opposed to 12 at higher resolutions.
' Note: GetTwips always takes the X RESOLUTION as its first
parameter.
sglFactorX = sglFactorX * (intTwipsPerPixelX / GetTwips(intX,
glrcXAxis))
sglFactorY = sglFactorY * (intTwipsPerPixelY / GetTwips(intX,
glrcYAxis))
End If

GetScreenScaleExit:
Exit Sub

GetScreenScaleError:
Select Case Err.Number
Case glrcErrDivisionByZero
' It seems that the first time you call
' GetDeviceCaps under Win95 after you've done
' a quick change on the resolution, it returns 0
' for the screen size. This will hopefully correct
' that problem.
Resume
Case Else
HandleError "GetScreenScale", Err.Number, Err.Description
Resume GetScreenScaleExit
End Select
End Sub

Private Function GetTwips(intXResolution As Integer, intAxis As Integer)

' Experience has shown that the twips/pixel ratios
' are dependent on the screen resolution. If you find this
' not to be true in your particular case, you'll need to modify
' this routine.

Select Case intXResolution
Case 1024, 1280
GetTwips = IIf(intAxis = glrcXAxis, _
glrcDesignXTwipsHiRes, glrcDesignYTwipsHiRes)
Case 640, 800
GetTwips = IIf(intAxis = glrcXAxis, _
glrcDesignXTwipsLoRes, glrcDesignYTwipsLoRes)
Case Else
' If the value is invalid, just assume the designed used
' a high-res screen. The worst this can do is cause
' an image that's a little small.
GetTwips = IIf(intAxis = glrcXAxis, _
glrcDesignXTwipsHiRes, glrcDesignYTwipsHiRes)
End Select
End Function

Function glrResizeForm(frm As Form, ByVal fDoResize As Variant, rctOriginal
As glrTypeRect)

' Called from the Resize event of forms.
' Attempt to resize the form and all its
' controls. Don't do anything if the
' current height of the form is 0, or if it's iconic.

' From Microsoft Access 95 Developer's Handbook
' by Litwin, Getz, Gilbert, and Reddick (Sybex)
' Copyright 1995. All rights reserved.

' In:
' frm: A reference to the form in question
' fDoResize: Yes/No (Actually do the resize, or just track the
information?)
' rctOriginal: the original coordinates
' Out:
' Nothing

Dim rctNew As glrTypeRect
Dim rctClient As glrTypeRect
Dim varTemp As Variant
Dim intWidth As Integer
Dim intHeight As Integer
Dim sglFactorX As Single
Dim sglFactorY As Single
On Error GoTo glrResizeWindowError
' Make sure the user hasn't sized this thing down
' to the nubs. If the client area is 0 height,
' it's time to call it quits.
glr_apiGetClientRect frm.hwnd, rctNew
intHeight = (rctNew.Y2 - rctNew.Y1)
If intHeight = 0 Or glr_apiIsIconic(frm.hwnd) Then
Exit Function
End If

' Get the current width. Already found the
' current height.
intWidth = (rctNew.X2 - rctNew.X1)

' Calc the scaling factor, given the current
' height/width and the previous height/width.
' Could be that rctOriginal has not yet been
' initialized, so trap for that error.

sglFactorX = intWidth / (rctOriginal.X2 - rctOriginal.X1)
sglFactorY = intHeight / (rctOriginal.Y2 - rctOriginal.Y1)

sglFactorOK:
' Store away the current values for
' the next time through here.
With rctOriginal
.X1 = rctNew.X1
.X2 = rctNew.X2
.Y1 = rctNew.Y1
.Y2 = rctNew.Y2
End With
' If the ratios are 1, there's nothing to do.
If (sglFactorX <> 1) Or (sglFactorY <> 1) Then
' If you actually want to do some resizing, do it now.
If fDoResize Then
SetFormSize frm, sglFactorX, sglFactorY, rctNew, False
End If
End If

glrResizeWindowExit:
Exit Function

glrResizeWindowError:
If Err = glrcErrDivisionByZero Then
sglFactorX = 1
sglFactorY = 1
Resume sglFactorOK
Else
HandleError "glrResizeForm", Err.Number, Err.Description
Resume Next
End If
End Function

Function glrScaleForm(frm As Form, intX As Integer, intY As Integer,
rctOriginal As glrTypeRect)

' Called from the Open event of forms.
' Attempts to scale the form appropriately
' for the given screen size, as compared
' to the size screen on which it was designed.

' From Microsoft Access 95 Developer's Handbook
' by Litwin, Getz, Gilbert, and Reddick (Sybex)
' Copyright 1995. All rights reserved.
'
' In:
' frm: A reference to the form in question
' intX: the horizontal screen resolution at which the form was
designed.
' intY: the vertical screen resolution at which the form was
designed.
' rctOriginal: original coordinates
'
' Out:
' Nothing
' Comments:
' Use a function call like this:
' intRetval = glrScaleForm(Me, 640, 480, rctOriginal)
' to autoscale a form created at 640x480 resolution.

Dim intTwipsPerPixelX As Integer
Dim intTwipsPerPixelY As Integer
Dim intScreenX As Integer
Dim intScreenY As Integer

Dim sglFactorX As Single
Dim sglFactorY As Single

GetScreenScale intX, intY, sglFactorX, sglFactorY

' Whether or not this form gets rescaled,
' you'll need to store away the current size
' for later. The reason you must call GetFormSize
' here, rather than glr_apiGetClientRect, is that
' you need the screen positioning information
' which you don't get with GetClientRect.
GetFormSize frm, rctOriginal

' If the x and y factors are both 1, there's nothing
' to do, so get out here.
If (sglFactorX = 1) And (sglFactorY = 1) Then Exit Function

' If you don't want forms to expand (they were created on a
' lower-resolution device than the current device), but only
' shrink (they were created on a higher-resolution device
' than the current device), then uncomment the next line.
'If (sglFactorX > 1) And (sglFactorY > 1) Then Exit Sub
DoCmd.RepaintObject
SetFormSize frm, sglFactorX, sglFactorY, rctOriginal, True
End Function
Private Sub HandleError(strFunction As String, intErr As Integer, strError
As String)
MsgBox "Error: " & strError & " (" & intErr & ")", vbExclamation,
strFunction
End Sub

Private Sub SetFormSize(frm As Form, sglFactorX As Single, sglFactorY As
Single, rct As glrTypeRect, fMove As Integer)

' Actually do the work to resize all the controls
' on the given form, and then resize the form
' itself.

Dim intTemp As Integer
Dim intWidth As Integer
Dim intHeight As Integer
Dim Ctl As Control
Dim sglFontSize As Single
Dim intI As Integer
Dim intGroups As Integer
Dim aGroups() As glrTypeDimensions
Dim colGroups As New Collection
Dim varTemp As Variant

On Error GoTo SetFormSizeError

DoCmd.Hourglass True
frm.Painting = False

' If the form is growing vertically, then need to
' fix up the section heights now. If it's shrinking,
' fix up the heights AFTER you place the controls.
' The same goes for the form width.
If sglFactorY > 1 Then
' Fix up all the section heights.
FixSections frm, sglFactorY
varTemp = frm.Width * sglFactorX
If varTemp > glrcMaxTwips Then
frm.Width = glrcMaxTwips
Else
frm.Width = varTemp
End If
End If

' Now deal with all the controls
' Go through and deal with all the groups and subforms first.
intGroups = FixGroups(frm, aGroups(), sglFactorX, sglFactorY)

' Now go back and deal with all the rest of the controls.
For Each Ctl In frm.Controls

Select Case Ctl.ControlType
Case acOptionGroup
GoTo NextCtl

Case acSubform
' If you've got a subform, then recurse on down into this
' routine again, dealing with all the controls inside of
' that subform.
SetFormSize Ctl.Form, sglFactorX, sglFactorY, rct, False

GoTo NextCtl
Case acPage
'an acPage, is a 'tab page' on a tab control
'The 'tab page' is automatically resized by the tab control
when the tab control itself is resized
'so.. don't resize the tab page. If the tab page WERE TO BE
resized, the tab control will automatically
'resize itself to match the page size (i.e. tab control
resizes increasing the page size, then page is resized
'increasing the tabcontrol size, then the next page is
resized, which again resizes everything etc, etc etc....
'the tab control would grow X times for each page on it)
GoTo NextCtl
End Select

' So the control isn't a subform and it's not a group.
' Therefore, just scale it to the correct size.

' First, fix up the font, if this control has a font
' that needs to be fixed up.
If ChangeFont(Ctl) Then
sglFontSize = Ctl.FontSize * sglFactorY
Else
sglFontSize = -1
End If

' Set the top, left and width values.

If frm.CurrentView <> acDatasheetView Then
Ctl.Top = Ctl.Top * sglFactorY
Ctl.Left = Ctl.Left * sglFactorX
Ctl.Width = Ctl.Width * sglFactorX
End If

' Change the height, if that's required.
If ChangeHeight(Ctl) Then
Ctl.Height = Ctl.Height * sglFactorY
End If

' Only attempt to change the font size for
' certain types of controls.
If sglFontSize >= 1 And sglFontSize <= 127 Then
Ctl.FontSize = sglFontSize
End If
NextCtl:
Next Ctl

' If the form is shrinking vertically, fix up the
' section heights now that all the controls have been
' placed. The same goes for the form width.
If sglFactorY < 1 Then
' Fix up all the section heights.
FixSections frm, sglFactorY
frm.Width = frm.Width * sglFactorX
End If

' Go through and fix up the option groups/subforms,
' which may have been distorted by changes to
' the internal controls.
For intI = 1 To intGroups
With frm(aGroups(intI).strCtlName)
.Top = aGroups(intI).sglTop
.Left = aGroups(intI).sglLeft
.Width = aGroups(intI).sglWidth
.Height = aGroups(intI).sglHeight
End With
Next intI

If fMove Then
intWidth = Int((rct.X2 - rct.X1) * sglFactorX)
intHeight = Int((rct.Y2 - rct.Y1) * sglFactorY)

rct.X1 = Int(rct.X1 * sglFactorX)
rct.Y1 = Int(rct.Y1 * sglFactorY)
rct.X2 = rct.X1 + intWidth
rct.Y2 = rct.Y1 + intHeight

intTemp = glr_apiMoveWindow(frm.hwnd, rct.X1, rct.Y1, intWidth,
intHeight, True)

' Use the Window-Size To Fit menu item.
DoCmd.DoMenuItem acFormBar, acWindow, acSizeToFit, , acMenuVer70

End If

SetFormSizeExit:
frm.Painting = True
DoCmd.Hourglass False
Exit Sub

SetFormSizeError:
Select Case Err
Case glrcErrInvalidProperty
Resume Next
Case Else
'HandleError "SetFormSize", Err.Number, Error.Description
Resume Next
End Select
End Sub


Nov 13 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Jozef wrote:
I have some old code that I use from the Access 95 Developers
handbook. The code works very well, with the exception that it
doesn't seem to recognize wide screens, and sizes tab controls so
that they are too big and wind up covering up some of the fields on
the main form.

Is there any good code out there that works in a similar fashion that
will also either a) stretch the form width wise on widescreens or b),
rely on height rather than width to resize the form. My VB skill
isn't that great, so I'm not able to modify this code to do what I
want. (I've pasted the code I'm using below).

Any ideas?


A question to consider first. Why do you think you need to make your app
larger on higher resolution screens? Do you see any other "normal" apps
that do this?

People run their screens at higher resolutions to see *more* stuff, not
*bigger* stuff.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #2

P: n/a
Rick Brandt wrote:
A question to consider first. Why do you think you need to make your app
larger on higher resolution screens? Do you see any other "normal" apps
that do this?

People run their screens at higher resolutions to see *more* stuff, not
*bigger* stuff.


Not always, some people have bad eyesight and despite this run at a high
resolution either from their own stupidity or something imposed on them
by their self esteemed IT departments.

I generally design a form so it looks neat, not with half the form's
controls out of the visible viewing area. Whether they run at 640x480 or
1600x1200 the application will look like the screen shot in the manual
and help file.

Where more controls are needed than fit in the window I design at, I
used to use page breaks on the form, nowdays I use a tab control.

I use the resizing code from the Access Developer's Handbook (Jozef take
note). It works well most of the time although I do generally modify
that code to take note of subforms that I don't want resized, those with
a gazillion columns across it so that when resized, they see more of the
subform and not a bigger view of it.

I do still get complaints about that, the users want the subform's
controls to get as big as the main form's ones as they say it's too
small, again despite me telling them that if the standard size font is
too small then they are running too high a resolution.

Nov 13 '05 #3

P: n/a
Trevor Best wrote:
Rick Brandt wrote:
A question to consider first. Why do you think you need to make
your app larger on higher resolution screens? Do you see any other
"normal" apps that do this?

People run their screens at higher resolutions to see *more* stuff,
not *bigger* stuff.


Not always, some people have bad eyesight and despite this run at a
high resolution either from their own stupidity or something imposed
on them by their self esteemed IT departments.


If someone buys a larger screen because of a sight impairment and then runs it
at a higher resolution than the smaller display that was replaced then that
suggests that their "impairment" extends beyond their eyesight.

My point stands. If a developer feels that his app is usable at 800 by 600 on a
15 inch monitor then he has no reason to make any of the forms larger when run
at a higher resolution. That setting was chosen by the user with certain
expectations. If they have trouble seeing any of their apps then they should
change the settings accordingly.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #4

P: n/a
Didn't mean to spark a debate, was just looking for an answer to my
question, or at least within the scope of the question . Even if there are
modifications that need to be made to the existing Developers Handbook code,
if you could give me an idea of what I need to do, or what part of the code
I need to look at / change that would be great.

Thanks!

"Rick Brandt" <ri*********@hotmail.com> wrote in message
news:sW***************@newssvr11.news.prodigy.com. .
Trevor Best wrote:
Rick Brandt wrote:
> A question to consider first. Why do you think you need to make
> your app larger on higher resolution screens? Do you see any other
> "normal" apps that do this?
>
> People run their screens at higher resolutions to see *more* stuff,
> not *bigger* stuff.
>


Not always, some people have bad eyesight and despite this run at a
high resolution either from their own stupidity or something imposed
on them by their self esteemed IT departments.


If someone buys a larger screen because of a sight impairment and then
runs it at a higher resolution than the smaller display that was replaced
then that suggests that their "impairment" extends beyond their eyesight.

My point stands. If a developer feels that his app is usable at 800 by
600 on a 15 inch monitor then he has no reason to make any of the forms
larger when run at a higher resolution. That setting was chosen by the
user with certain expectations. If they have trouble seeing any of their
apps then they should change the settings accordingly.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com

Nov 13 '05 #5

P: n/a
Jozef wrote:
Didn't mean to spark a debate, was just looking for an answer to my
question, or at least within the scope of the question . Even if
there are modifications that need to be made to the existing
Developers Handbook code, if you could give me an idea of what I need
to do, or what part of the code I need to look at / change that would
be great.


As far as I know all of the limitations that were present in resizing code
gimmicks in the past are still there. They have problems with certain
controls (tabs, subforms), and they are a lot better at making forms bigger
than they are at making them smaller (which in my opinion is their only
legitimate purpose).

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #6

P: n/a
Look at "Peter's Software" resizing utility.
http://www.peterssoftware.com/ss.htm

I've used it for customers who insist on running their monitors at 640x400,
but in the long run, it's easier to dump these quirky clients, then waste
resources supporting a very small minority.
-Ed
"Jozef" <me@you.com> wrote in message news:AJR2f.22002$ir4.8054@edtnps90...
Didn't mean to spark a debate, was just looking for an answer to my
question, or at least within the scope of the question . Even if there
are modifications that need to be made to the existing Developers Handbook
code, if you could give me an idea of what I need to do, or what part of
the code I need to look at / change that would be great.

Thanks!

"Rick Brandt" <ri*********@hotmail.com> wrote in message
news:sW***************@newssvr11.news.prodigy.com. .
Trevor Best wrote:
Rick Brandt wrote:
> A question to consider first. Why do you think you need to make
> your app larger on higher resolution screens? Do you see any other
> "normal" apps that do this?
>
> People run their screens at higher resolutions to see *more* stuff,
> not *bigger* stuff.
>

Not always, some people have bad eyesight and despite this run at a
high resolution either from their own stupidity or something imposed
on them by their self esteemed IT departments.


If someone buys a larger screen because of a sight impairment and then
runs it at a higher resolution than the smaller display that was replaced
then that suggests that their "impairment" extends beyond their eyesight.

My point stands. If a developer feels that his app is usable at 800 by
600 on a 15 inch monitor then he has no reason to make any of the forms
larger when run at a higher resolution. That setting was chosen by the
user with certain expectations. If they have trouble seeing any of their
apps then they should change the settings accordingly.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com


Nov 13 '05 #7

P: n/a
Ed Robichaud wrote:
Look at "Peter's Software" resizing utility.
http://www.peterssoftware.com/ss.htm

I've used it for customers who insist on running their monitors at 640x400,
but in the long run, it's easier to dump these quirky clients, then waste
resources supporting a very small minority.
-Ed


I wish I could drop clients who make life difficult with their quirks,
if I had a lot of little clients I could but I have a few big ones and
dropping one would be a big financial mistake.
Nov 13 '05 #8

P: n/a
Jozef wrote:
Didn't mean to spark a debate, was just looking for an answer to my
question, or at least within the scope of the question . Even if there are
modifications that need to be made to the existing Developers Handbook code,
if you could give me an idea of what I need to do, or what part of the code
I need to look at / change that would be great.


In the class module, FormResize, look for the comment that begins with
"' Luckily"
' If you've got a subform control,
' call the whole thing recursively.
' Luckily, this can't go more than 2 levels deep.
If ctl.ControlType = acSubform Then
If ScaleThisForm And Len(ctl.SourceObject) > 0 Then
If InStr(1, ctl.Form.Tag, ":skipresize:") = 0 Then
Call ctlr.frm.ScaleFormContents(decFactorX, decFactorY)
End If
End If
End If
Next ctlr

This skips the subform if the tag is set, and also subforms that don't
yet have a sourceobject set as this used to error a lot.
Nov 13 '05 #9

P: n/a
"Trevor Best" wrote
' If you've got a subform control,
' call the whole thing recursively.
' Luckily, this can't go more than 2 levels deep.


Unluckily, perhaps, the nesting level has been increased from 3 to 10,
though, IMNSHO, a 10-level nesting of subforms would be unworkable.

Larry Linson
Microsoft Access MVP
Nov 13 '05 #10

P: n/a
Larry Linson wrote:
"Trevor Best" wrote
> ' If you've got a subform control,
> ' call the whole thing recursively.
> ' Luckily, this can't go more than 2 levels deep.


Unluckily, perhaps, the nesting level has been increased from 3 to 10,
though, IMNSHO, a 10-level nesting of subforms would be unworkable.


I should point out that it was ADH's comment, not mine, I'm blissfully
unaware of any nesting limitations :-)

I've not had to nest a subform since I did an asset management module
whereby I had to frig it in Access 2.0 so my first level subform wasn't
a subform at all but controls on the screen and a scrollbar control
alongside to emulate a scrolling subform.

Whenever I need another level down noawdays, I use a drill down method
so there's one subform, say order items, then double click to bring up a
main form with that item on and have subforms on that form for things
like cost distribution (budgets), tag numbers, etc.
Nov 13 '05 #11

P: n/a
Thanks folks!

"Rick Brandt" <ri*********@hotmail.com> wrote in message
news:2Z***************@newssvr25.news.prodigy.net. ..
Jozef wrote:
Didn't mean to spark a debate, was just looking for an answer to my
question, or at least within the scope of the question . Even if
there are modifications that need to be made to the existing
Developers Handbook code, if you could give me an idea of what I need
to do, or what part of the code I need to look at / change that would
be great.


As far as I know all of the limitations that were present in resizing code
gimmicks in the past are still there. They have problems with certain
controls (tabs, subforms), and they are a lot better at making forms
bigger
than they are at making them smaller (which in my opinion is their only
legitimate purpose).

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com

Nov 13 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.