It's OK if you have only one detail row.
In SQL query I calculate how many detail rows I have for each master row and then multiply it with iDetailData1_Height.
No, I have multiple detail rows. as I mentioned earlier I didn't want in my report to find any master header alone in the bottom of the page, your code works perfectly but there are a lot of blank space can be used for the next master and some of their detail data, so I edited the code to make sure if this part of page doesn't fit one master +at least one detail data then force new page , and I could never guess that without your instruction.