Hi
I apologize if this has already been answered, but I can't find it. I want to specify the height of a continuous form (not modal, not popup, not autocentered) (maybe only the detail section ?) so that it equals the height of what I think is the Access application client area rectangle. I could just maximize the form but sometimes I will have at least 2 forms open at the same time. I don't like using tabbed documents since you can't see more than 1 object at a time. I also use multiple access apps on 3 different sized monitors, and not always with the Access app maximized. Thus I want to get and understand the Access application client area rectangle.
First question: exactly what is the Access app client area rectangle ? My understanding is that it is the area within Access in which I can display objects (tables, forms, macros, queries). Does it include the menu bar, ribbon, database container window, status bar ?
When I use the below code, the form height is too big, so the Access vertical scroll bar appears.
I'm using:
Access Microsoft Access 2016 - Build:16.0.12827 (32 bit)
Windows 10 Pro version 1909 Build 18363 64 bit
Thanks
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Sub WindowSize(ByRef Height As Long, ByRef Width As Long, hwnd As Long, ByRef Top As Long, ByRef Bottom As Long)
'Dim hwnd As Long
Dim rct As RECT
If hwnd = 0 Then
hwnd = FindWindow(vbNullString, "Database1")
If GetClientRect(hwnd, rct) <> 0 Then
'If GetWindowRect(hwnd, rct) <> 0 Then
Height = (rct.Bottom - rct.Top) * TwipsPerPixel("Y")
Width = (rct.Right - rct.Left) * TwipsPerPixel("X")
Bottom = rct.Bottom * TwipsPerPixel("X")
End If
Else
If GetClientRect(hwnd, rct) <> 0 Then
Height = (rct.Bottom - rct.Top) * TwipsPerPixel("Y")
Width = (rct.Right - rct.Left) * TwipsPerPixel("X")
Bottom = rct.Bottom * TwipsPerPixel("Y")
End If
End If
End Sub
Public Function TwipsPerPixel(strDirection As String) As Long
'Handle to device
Dim lngDC As Long
Dim lngPixelsPerInch As Long
Const nTwipsPerInch = 1440
lngDC = GetDC(0)
If (Left$(strDirection, 1) = "X") Then 'Horizontal
lngPixelsPerInch = GetDeviceCaps(lngDC, WU_LOGPIXELSX)
Else 'Vertical
lngPixelsPerInch = GetDeviceCaps(lngDC, WU_LOGPIXELSY)
End If
lngDC = ReleaseDC(0, lngDC)
TwipsPerPixel = nTwipsPerInch / lngPixelsPerInch
End Function
Private Sub buCmd1_Click()'on a form button on click event
Dim intAppWindowHeight As Long
Dim intAppWindowWidth As Long
Dim intFrmWindowHeight As Long
Dim intFrmWindowWidth As Long
intRibbonHeight = Application.CommandBars("Ribbon").Height
WindowSize intAppWindowHeight, intAppWindowWidth, 0
WindowSize intFrmWindowHeight, intFrmWindowWidth, Me.hwnd
'I've tried all the below but the form is always to tall
docmd.movesize 0, 0, , intAppWindowHeight
me.insideHeight = intAppWindowHeight
docmd.movesize 0, 0, , intAppWindowHeight - intRibbonHeight
me.insideHeight = intAppWindowHeight - intRibbonHeight
end sub
I apologize if this has already been answered, but I can't find it. I want to specify the height of a continuous form (not modal, not popup, not autocentered) (maybe only the detail section ?) so that it equals the height of what I think is the Access application client area rectangle. I could just maximize the form but sometimes I will have at least 2 forms open at the same time. I don't like using tabbed documents since you can't see more than 1 object at a time. I also use multiple access apps on 3 different sized monitors, and not always with the Access app maximized. Thus I want to get and understand the Access application client area rectangle.
First question: exactly what is the Access app client area rectangle ? My understanding is that it is the area within Access in which I can display objects (tables, forms, macros, queries). Does it include the menu bar, ribbon, database container window, status bar ?
When I use the below code, the form height is too big, so the Access vertical scroll bar appears.
I'm using:
Access Microsoft Access 2016 - Build:16.0.12827 (32 bit)
Windows 10 Pro version 1909 Build 18363 64 bit
Thanks
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Sub WindowSize(ByRef Height As Long, ByRef Width As Long, hwnd As Long, ByRef Top As Long, ByRef Bottom As Long)
'Dim hwnd As Long
Dim rct As RECT
If hwnd = 0 Then
hwnd = FindWindow(vbNullString, "Database1")
If GetClientRect(hwnd, rct) <> 0 Then
'If GetWindowRect(hwnd, rct) <> 0 Then
Height = (rct.Bottom - rct.Top) * TwipsPerPixel("Y")
Width = (rct.Right - rct.Left) * TwipsPerPixel("X")
Bottom = rct.Bottom * TwipsPerPixel("X")
End If
Else
If GetClientRect(hwnd, rct) <> 0 Then
Height = (rct.Bottom - rct.Top) * TwipsPerPixel("Y")
Width = (rct.Right - rct.Left) * TwipsPerPixel("X")
Bottom = rct.Bottom * TwipsPerPixel("Y")
End If
End If
End Sub
Public Function TwipsPerPixel(strDirection As String) As Long
'Handle to device
Dim lngDC As Long
Dim lngPixelsPerInch As Long
Const nTwipsPerInch = 1440
lngDC = GetDC(0)
If (Left$(strDirection, 1) = "X") Then 'Horizontal
lngPixelsPerInch = GetDeviceCaps(lngDC, WU_LOGPIXELSX)
Else 'Vertical
lngPixelsPerInch = GetDeviceCaps(lngDC, WU_LOGPIXELSY)
End If
lngDC = ReleaseDC(0, lngDC)
TwipsPerPixel = nTwipsPerInch / lngPixelsPerInch
End Function
Private Sub buCmd1_Click()'on a form button on click event
Dim intAppWindowHeight As Long
Dim intAppWindowWidth As Long
Dim intFrmWindowHeight As Long
Dim intFrmWindowWidth As Long
intRibbonHeight = Application.CommandBars("Ribbon").Height
WindowSize intAppWindowHeight, intAppWindowWidth, 0
WindowSize intFrmWindowHeight, intFrmWindowWidth, Me.hwnd
'I've tried all the below but the form is always to tall
docmd.movesize 0, 0, , intAppWindowHeight
me.insideHeight = intAppWindowHeight
docmd.movesize 0, 0, , intAppWindowHeight - intRibbonHeight
me.insideHeight = intAppWindowHeight - intRibbonHeight
end sub