Can you tell me why it happens:

if I write next thing (in subreport's OnFormat) everything is okay and works properly:

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If Reports!CommercialDocuments_T3.Pages = 0 Then
        Exit Sub
    End If

    Static nReset As Long
    
    If nReset = 1 Then
        Section(acDetail).ForceNewPage = 0
        nReset = 0
    End If
    
    If CurrentRecord = Recordset.RecordCount - 1 Then
        Section(acDetail).ForceNewPage = 2
        nReset = 1
    End If
End Sub
If I add next check (it checks if I have space left to print text after the sub report where the height is nHeightRequired) everything stops working.

Code:
    If LogicalPageHeight - nBottom < nHeightRequired Then
        If CurrentRecord = Recordset.RecordCount - 1 Then
            Section(acDetail).ForceNewPage = 2
            nReset = 1
        End If
    End If
OnFormat() function is called two times with the same data (excluding calls with Parent.Page = 0) but with different Report.Top values. Because of this on the first run it won't set ForceNewPage to 2 and on the second it will! Why does it happen? And why if I set ForceNewPage to 2 during both runs everything works and otherwise doesn't.