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
'All my pop up forms
Public Sub FormMoveResize(Frm As Form)
Dim W As Long 'Width (centimeters)
Dim H As Long 'High (centimeters)
Select Case Frm.Name
Case "Contoare_tipuri"
W = 12: H = 14
Case "Repartitoare_tipuri"
W = 12: H = 14
Case "Tevi"
W = 11: H = 14
Case "Kc_tevi"
W = 12: H = 7
Case "Kc_radiatoare"
W = 12: H = 7
Case "Ramificatii_SETuri_tevi"
W = 13: H = 14
Case "Ramificatii_SETuri_radiatoare"
W = 13: H = 14
Case "Radiatoare"
W = 12: H = 14
Case "Noduri_CI"
W = 14: H = 16
Case "Incinte_Denumiri"
W = 9: H = 14
Case "Incinte_CI_Tevi"
W = 10: H = 14
Case "Incinte_CI_radiatoare"
W = 10: H = 14
Case "Incinte_CD_tevi"
W = 10: H = 14
Case "Incinte_CD_radiatoare"
W = 10: H = 14
Case "Incinte_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
End Sub
'Convert units. Actually this function convert only centimeters in twips
'FROMum = From measurement unit
'TOum = To measurement unit
FROMval = number of units
Public Function Conv(FROMum As String, TOum As String, FROMval)
Select Case FROMum
Case "Cm" 'Centimeter
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