Subreport is executing the Detail_Format two full times

41 Views Asked by At

I am working on a genealogy database with children, parents, grandparents, etc. The one report giving trouble has the typical Report Header and Footer with a detail section in the middle, and the subreport giving trouble is in the Report Footer.

VBA code in the subreport of the Detail_Format is to determine which person in the family is displayed and how they are formatted. In nearly every case, the last person in the family is hidden so the Detail.Visible has been set to false. The problem is when running the report, the first person is also hidden.

Adding a line counter to the detail section I found that the query results were running a full two times. On the second iteration, the first person in the list is hidden because txtPrevGen still holds the value of the last person in the query from the first result set.

txtCount.ControlSource = "=1"  
txtCount.RunningSum = "Over Group"

VBA code for the Detail_Format in the subreport:

    Debug.Print txtCount
    
    If Nb(txtPrevGen, 0) > 3 Then
        Detail.Visible = False
    Else
        txtPerson = DLookup("fldFirstName & ' ' & fldLastName", "tblPeople", "fldID = " & txtPersonID)
    End If
    
    txtPrevGen = txtGeneration

If there are 4 records in the query, the debug results are:

1
2
3
4
1
2
3
4

There is no other place to indicate this subreport is being called or fired multiple times. So how can the query results re-run a second time starting from the first record?

0

There are 0 best solutions below