06/05/2025 - Scolaretto ha scritto:
Yes , comunque più che contenuta direi eseguita da form .
Più o meno.... .... Esempio:

Purtroppo ci sono diversi vincoli secondo se la form è Popup oppure no , se è in visualizzazione form oppure maschere continue oppure foglio dati.
Non puoi utilizzare certe proprietà o non vengono esposte.
Insomma... graficamente MsAccess ha tanti limiti e anche come sugli eventi....
In questo caso per la Form sarà una cosa di questo tipo :
Esempio richiamando da FORM LOAD oppure vedi te da altro evento che ritieni opportuno....
Option Compare Database
Option Explicit
Private maxHeightForm As Long ' Maximun heigth of the form
' FORM LOAD
Private Sub Form_Load()
' Resize form
Call MyResizeForm
End Sub
' RESIZE FORM
Private Sub MyResizeForm()
On Error Resume Next
Dim nRows As Long
Dim heightRow As Long
Dim heightExtra As Long
Dim minHeightForm As Long
Dim heightHeader As Long
Dim heightFooter As Long
Dim newHeightForm As Long
' Retrieve form valus
With Me.Form
' Retrieve recordcount
.Recordset.MoveLast
.Recordset.MoveFirst
nRows = .Recordset.RecordCount
' Retrieve row height
heightRow = .Section(acDetail).Height
' Retrive header and footer height
If .Section(acHeader).Visible Then heightHeader = .Section(acHeader).Height
If .Section(acFooter).Visible Then heightFooter = .Section(acFooter).Height
End With
' To be set if the form has the new record row
heightExtra = heightRow * 1
' Minimum height of the form window
minHeightForm = heightHeader + heightFooter + heightRow + heightExtra
' Maximun heigth of the form windows
If maxHeightForm = 0 Then maxHeightForm = Me.InsideHeight
' Check if rows exists
If nRows > 0 Then
' Calculate new height size form
newHeightForm = (nRows * heightRow) + heightExtra + heightHeader + heightFooter
' Check min and max height form
If newHeightForm > maxHeightForm Then newHeightForm = maxHeightForm
If newHeightForm < minHeightForm Then newHeightForm = minHeightForm
' Set new height size form
Me.InsideHeight = newHeightForm
Else
' Set minimun height form if no rows exist
Me.InsideHeight = minHeightForm
End If
End Sub
.
In questo caso, rispetto al precedente con subForm, non devi cambiare/sostituire nessun nome perchè si lavora esclusivamente con la Me.
Verifica e fai test... dovrebbe andare bene
Prova a provare :-)
.
ATTENZIONE !!! Ricordati che le dimensioni in altezza della Form non le puoi impostare nelle prorpietà Form.
L'altezza della Form viene assunta al salvataggio uscendo dalla Modalità Struttura (di Designer)
Solo qui puoi stabilire l'altezza della Form, trascini in alto o in basso il bordo della finestra e salvi.
Da quel momento in poi l'altezza della finestra è definita e cambierà solo se salvi una nuova impostazione ritornando in progettazione Modalità Struttura.
Quindi in questo caso di resize sulla base dei records da visualizzare, la dimensione Iniziale dell'altezza della Form viene data da come è stata salvata in progettazione Modalità Struttura. Questa dimensione risulterà essere l'altezza massima che potrà avere la Form in fase di Resize.