Sizing forms problem

Lateral

Registered User.
Local time
Today, 15:45
Joined
Aug 28, 2013
Messages
388
Hi guys

I'm a newbie and am pulling my hair out with this one....

I need somebody to tell me in a simple step by step the correct way and properties to set that will enable me to size any form to the exact size that I want as I must be doing something wrong as I have some forms that no matter what I do, they always want to be bigger than the screen size!

I need the majority of my forms to be automatically maximised to make it easy for the user and have used the following code on the first form that is used:

Private Sub Form_Load()
DoCmd.Maximize
End Sub

Help!

Thanks

Regards
Greg
 
Hi Alex,

I have Overlapping Windows set on.

Regards
Greg
 
You could switch to tabbed but that might not fit with your process.

You could look into the insidewidth/insideheight properties of a Form.

Here's a Tip video on the matter that might be useful.
http://www.599cd.com/tips/access/misc/AC310-resize-form-vba.asp?key=AlexForum

This can set to specific sizes if used in the on open or load events.

-
For the maximise code you've been using does it ever run?
 
Hi Alex,

Thanks for the video. I'll try it and let you know if it works.

Thanks again for your help.
Regards
Greg
 
Hi Alex,

I looked at the video and implemented the displaying of the width and height and also hard coding the dimensions without success.

This is the scenario.

1. The form (lets call it "Parts") was created using the form create wizard of Access 2007.
2. I display the form via a menu item in one form (form A) and via a double click on a record in a subform in another form (form B).
3. I have added the following code to the "On load" setting for the form:

Private Sub Form_Load()
Me.InsideHeight = 5475
Me.InsideWidth = 16000
End Sub

4. When I load Parts from form A, it displays ok but with the dimensions, 5475 x 23430. It has minimise, maximise and close buttons.

5. When I load Parts from form B, it displays incorrectly with the dimensions 5474 x 78825 without the minimize or maximise buttons. It just has the close button!

What's going on!!!

arghhhh!

Regards
Greg
 
Last edited:
This is tested code from one of my DB

I wish to open the form frmContoare_tipuri
Code:
Private Sub cmdContoare_Click()
    DoCmd.OpenForm "[B]frmContoare_tipuri[/B]", , , , , acDialog
End Sub
The Open event for frmContoare_tipuri
Code:
Private Sub Form_Open(Cancel As Integer)
    Call FormMoveResize(Me)
End Sub
Code in a public (regular) module:
Code:
Option Compare Database
Option Explicit

' API declarations:
Private Declare Function apiGetClientRect Lib "user32" Alias "GetClientRect" (ByVal hwnd As Long, lpRect As typRect) As Long
Private Declare Function apiGetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As typRect) As Long
Private Declare Function apiSetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

' Type declarations:
Private Type typRect
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

' Constant declarations:
Private Const SW_RESTORE = 9
Private Const SWP_NOSIZE = &H1 ' Don't alter the size
Private Const SWP_NOZORDER = &H4 ' Don't change the Z-order
Private Const SWP_SHOWWINDOW = &H40 ' Display the window

' **************************************
' * Center a form in the Access window *
' **************************************
' Created 1-22-2002 by Peter M. Schroeder

'Mod apelare: Call gfncCenterForm(Me)

Public Function gfncCenterForm(parForm As Form) As Boolean
    Dim varAccess As typRect, varForm As typRect
    Dim varX As Long, varY As Long
    
    On Error GoTo CenterForm_Error
    Call apiGetClientRect(hWndAccessApp, varAccess) ' Get the Access client area coordinate
    Call apiGetWindowRect(parForm.hwnd, varForm) ' Get the form window coordinates
    varX = CLng((varAccess.Left + varAccess.Right) / 2) - CLng((varForm.Right - varForm.Left) / 2) ' Calculate a new left for the form
    varY = CLng((varAccess.Top + varAccess.Bottom) / 2) - CLng((varForm.Bottom - varForm.Top) / 2) ' Calculate a new top for the form
    varY = varY - 45 ' Adjust top for true center
    varY = varY - 20 ' Adjust top for appearance
    Call apiShowWindow(parForm.hwnd, SW_RESTORE) ' Restore form window
    Call apiSetWindowPos(parForm.hwnd, 0, varX, varY, (varForm.Right - varForm.Left), (varForm.Bottom - varForm.Top), SWP_NOZORDER Or SWP_SHOWWINDOW Or SWP_NOSIZE) ' Set new form coordinates
    gfncCenterForm = True
    Exit Function
    
CenterForm_Error:
    gfncCenterForm = False
End Function

Public Sub FormMoveResize(Frm As Form)
Dim W As Long 'Latime (in centimetri)
Dim H As Long 'Inaltime (in centimetri)
    Select Case Frm.Name
        [B]Case "frmContoare_tipuri"
            W = 12: H = 14[/B]
'Other forms in my DB that need to be sized
        Case "frmRepartitoare_tipuri"
            W = 12: H = 14
        Case "frmTevi"
            W = 11: H = 14
        Case "frmKc_tevi"
            W = 12: H = 7
        Case "frmKc_radiatoare"
            W = 12: H = 7
        Case "frmRamificatii_SETuri_tevi"
            W = 13: H = 14
        Case "frmRamificatii_SETuri_radiatoare"
            W = 13: H = 14
        Case "frmRadiatoare"
            W = 12: H = 14
        Case "frmNoduri_CI"
            W = 14: H = 16
        Case "frmIncinte_Denumiri"
            W = 9: H = 14
        Case "frmIncinte_CI_Tevi"
            W = 10: H = 14
        Case "frmIncinte_CI_radiatoare"
            W = 10: H = 14
        Case "frmIncinte_CD_tevi"
            W = 10: H = 14
        Case "frmIncinte_CD_radiatoare"
            W = 10: H = 14
        Case "frmIncinte_Radiatoare"
            W = 15: H = 14
        Case Else
            Debug.Print Frm.Name
            Stop
            Exit Sub
    End Select
    
    With Frm
        DoCmd.MoveSize , , Conv("Cm", "Twip", W), Conv("Cm", "Twip", H)
        Call gfncCenterForm(Frm)
    End With
    
    Call BeepOnce(1)
End Sub

Public Function Conv(FROMum As String, TOum As String, FROMval)
'Convert units (for now work only from Cm to Twips)
    Select Case FROMum
        Case "Cm" 'Centimetri
            Select Case TOum
                Case "Twip" 'twips
                    Conv = FROMval * 566.929133858
                Case Else
                    Stop
                    Exit Function
            End Select
            
        Case Else
            Stop
            Exit Function
    End Select
End Function

This code will center the form but you can adapt it in order to move the form.

Good luck !
 

Users who are viewing this thread

Back
Top Bottom