Hai fatto ???
dai, ti faccio vedere come ho fatto, devi solo verificare le Altezze, come ti ho spiegato sopra, nella parte di codice :
' Set Values in twip -> 1 cm = approximately 567 twip
heightRow = 310 ' row height
heightExtra = 640 ' to be set if the subform has the new record row
maxHeightSubform = 6000 ' maximum height of the subform
minHeightSubform = 2200 ' minimum height of the subform window
poi devi verificare il calcolo delle righe presenti nella SubForm nella parte di codice : (sostituire MySubForm con il nome della tua subform)
' Retrieve subform valus
With Me.MySubForm.Form
' Retrieve recordcount
.Recordset.MoveLast
.Recordset.MoveFirst
nRows = .Recordset.RecordCount
.
Adesso metti tutto insieme e richiami la routine per esempio nell'evento
Private Sub Form_Current()
Call MyResizeSubForm
End Sub
Oppure in qualsiasi altro evento (per esempio su Form Load) che viene richiamato a fronte dell'aggiornamento delle righe nella subform.
Questo lo devi determinare tu, dove e quando....
' RESIZE SUB FORM
Private Sub MyResizeSubForm()
On Error Resume Next
Dim nRows As Long
Dim heightRow As Long
Dim heightExtra As Long
Dim maxHeightSubform As Long
Dim minHeightSubform As Long
Dim heightHeader As Long
Dim heightFooter As Long
Dim newHeightSubForm As Long
' Set Values in twip -> 1 cm = approximately 567 twip
heightRow = 310 ' row height
heightExtra = 640 ' to be set if the subform has the new record row
maxHeightSubform = 6000 ' maximum height of the subform
minHeightSubform = 2200 ' minimum height of the subform window
' Retrieve subform valus
With Me.MySubForm.Form
' Retrieve recordcount
.Recordset.MoveLast
.Recordset.MoveFirst
nRows = .Recordset.RecordCount
' 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
' Check if rows exists
If nRows > 0 Then
' Calculate new height size subform
newHeightSubForm = (nRows * heightRow) + heightExtra + heightHeader + heightFooter
' Check min and max height subform
If newHeightSubForm > maxHeightSubform Then newHeightSubForm = maxHeightSubform
If newHeightSubForm < minHeightSubform Then newHeightSubForm = minHeightSubform
' Set new height size subform
Me.MySubForm.Height = newHeightSubForm
Else
' Set minimun height subform if no rows exist
Me.MySubForm.Height = minHeightSubform
End If
End Sub
.
FATTO !!!
Impostati i valori, calcolandoli come ti ho spiegato sopra, poi li aggiusti al millimetro eseguendo la form con la sua subform...
Prova a provare ... sono solo calcoli, non fanno male ! ;-)